- How does the react-router get history objects?
- Wrap the Route component in compoent and he’ll inject the history object, or wrap the withRouter with a higher-order component
- React-router How to obtain URL parameters?
- match.params
- What is the difference between push and replace in History mode?
- PushState (null, “,path); pushState(null, “,path);
- Replace means to replace the current record
- How to configure redirection on the React-Router?
- The package uses redirect in the Switch, setting the FROM and to properties
- How many types of Router components are available in React-Router 4?
BrowserRouter and hashRouter
- What is the implementation principle of react-Router?
BrowserRouter works by listening for window. onpopState and enhancing histroy.pushState to change the context’s content to pass to child components when history changes. The Route re is then used to match the URL path and inject the history object into the matching component.
A hashRoueter listens for window.addeventListener (‘hashchange’,()=>{}) and passes hash changes to child components using the contents of the context. The Route re is then used to match the URL path and inject the history object into the matching component.
- What is the use of the React-router 4 switch?
Matches the first path to return
- How does react-Router 4 re-render the same component when the route changes?
You can determine route changes during the lifecycle and do re-rendering logic, such as useEffect and componentdidUpdate
- What is the difference between the Link tag and the A tag of the React-router?
The Link tag basically adds the to function to jump to the specified route, which essentially implements the history.push method
- What are the differences between React routes and common routes?
Static routing is when you start the application you load all the routing modules in dynamic routing is when you go to this page, you load the components