Home >Web Front-end >Vue.js >[Compilation and sharing] Some vue-router related interview questions (with answer analysis)
This article will summarize and share with you some vue-router related interview questions (with answer analysis), help you sort out the basic knowledge, and enhance the vue-router knowledge reserve. It is worth collecting, come and take a look!
In a single-page application, switching between different components needs to be implemented through front-end routing .
Front-end routing
1.key is the path, value is the component, used to display the page content
2. Working process: when the browser's path changes , the corresponding component will be displayed. vue-router
’s routing function: Map components to routes and then render them
Mainly
How to change the URL without causing the page to refresh
How to detect the URL change [Related recommendations: vuejs video tutorial, web front-end development 】
hash is the ## in the URL ## and the following part, the URL after
# will not be sent to the server,
so changing the hash part in the URL will not cause the page to refresh
onhashchange event changes. When the hash changes, read the content after
#, match routing rules based on the information, and change the page routing by changing
window.location.hash.
Three ways to change the URL
Advantages
The hash value needs to be preceded by #, which does not comply with the url specification and is not beautiful
#html5 # Method, used to add and modify records in the browsing history, change the page path,
so that the URL jump will not reload the page.
hashchange event, but the popstate event is somewhat different:
Only when making the browser popState will be called only when behavior
is triggered. It will be triggered when the user clicks the browser's back button and forward button, or uses JavaScript to call the History.back(), History.forward(), and History.go() methods.
Conforms to URL address specifications, no # is required, and it is more beautiful to use
When the user
manually enters the address or refreshes the page, a url request method requires the support of a specific browser.
How to specify the jump route | If no parameters are passed | Can parameters be passed without the required value | ||
---|---|---|---|---|
Path/params parameter | You must use name to specify the route | params is part of the route , If placeholders are configured, If this route has params parameters, but this parameter is not passed during the jump, the jump will fail or the page will have no content. |
Placeholders that are not included in the delivery path will not be displayed on the address bar and will be lost upon refresh |
query parameters |
Path? key1=val1 & key2=val2.... |
1. You can use name to specify the route 2. You can use path to specify the route |
query It is a parameter spliced after the url. It doesn’t matter if it is not available. | query will not
The above is the detailed content of [Compilation and sharing] Some vue-router related interview questions (with answer analysis). For more information, please follow other related articles on the PHP Chinese website!