GithubHelp home page GithubHelp logo

router-principle's Introduction

router原理简单封装

注: 1.demo为react-router-dom 2.使用 source为封装代码,核心代码在src/router

我们只关心两件事:

  • 1.点击超链接是否会跳转
  • 2.点击浏览器前进/后退是否能达到页面不刷新,且地址栏变化且组件产生变化

hash路由原理

图片

当为hash模式时,浏览器不管在超链接跳转和地址栏变化,都会执行hashchange,所以我们只需监听hashchange进行相应的处理

history路由原理

图片

当为history模式时,超链接跳转时阻止a标签的默认事件,进行处理

前进后退时监听popstate,进行页面以及地址栏变化

router-principle's People

Contributors

snapea avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.