1. Installation process
- Through the
mixin
global injectionbeforeCreate
hook, injected when the component is initialized_routerRoot
- Use
Object.defineproperty
mounts$router
and$route
parameters - Global injection
RouterView
andRoterLink
components - Define merger strategy
2. Instantiate Router
- Parse configuration generation
matcher
- Judge the environment instantiation
history
object
3. Route Jump
- The
beforeCreate
hook is triggered when the root component is instantiated ,Router
theinit
method called , binds the global routing monitoring event, performs the first routing jump and responsive processingthis._route
- After triggering the route jump, execute
Router.history
the jump method on - Analyze the route, extract the hook, execute the hook, confirm and update the route to trigger the response, modify
url
, trigger theafter
hook - The next event loop responsively triggers view updates and renders new routing components
4. Route rendering
RouterView
Therender
function is defined internally , and executed every time it is re-rendered,route
the corresponding component will be parsed according to the current, and the corresponding component will be used to replace itself for rendering. If there is no component, it will be rendered as a comment node
The props method of routing parameters is to parse out the parameters after matching the components, and finally participate in the creation of the component's vnode in the form of component data to realize the props passing parameters.
RouterLink
Internally definedrender
functions are executed each time it is re-rendered, events are defined according to the passed parameters, and finally rendered intoa
labels and bound to corresponding events