1. Global beforeEachWhen the name stored in Local Storage is zhangsan, the message content will be displayed only when the message is clicked 1. Global beforeEach
grammar: router.beforeEach((to, from, next)=>{})
2. Implementation2. Requirement 2If there are many paths that need to be judged before jumping, you need to write a lot of judgment code, and the judgment structure will be very complicated. At this time, you can put a meta tag in the route that needs to be judged. The meta tag provides metadata about the HTML document (metadata refers to data used to describe data) At this time, you can use the tag field in meta to make a judgment 3. Global post-guard afterEach The usage of afterEach and beforeEach is basically the same. The difference is that afterEach does not have the next parameter 1. Change the title to your own titleAssign each route its own title name const router = new VueRouter({ routes: [ { name: 'home', path: '/home', component: Home, meta: { title: "Home" }, children: [ { name: "xiaoxi", path: 'message', component: Message, meta: { title: "News" }, children: [ { name: 'xiangqing', path: 'detail', component: Detail, meta: { isAuth: true, title: "Message Details" } } ] } ] }, { path: '/about', component: About, meta: { title: "About" } } ] }) Modify the title name in beforeEach router.afterEach((to, from) => { document.title = to.meta.title || "Test" }) 4. Guarding within components1. beforeRouteEnterCalled when entering this component through routing rules 2. beforeRouteLeaveCalled when leaving the component through routing rules SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: How to stop CSS animation midway and maintain the posture
>>: A Guide to Optimizing High-Performance Websites
1. js will not protect hasOwnProperty from being ...
1. Grid layout (grid): It divides the web page in...
Docker tag detailed explanation The use of the do...
1. Scroll Snap is a must-have skill for front-end...
This article introduces RHEL8 network services an...
Table of contents 1. Error phenomenon 2. Error An...
Although head and DTD will not be displayed on th...
1 Implementation Principle This is done using the...
Preface This article mainly introduces the releva...
What are :is and :where? :is() and :where() are p...
The database queries which object contains which ...
Table of contents 1. Introduction 2. Advantages 3...
I searched on Baidu. . Some people say to use the...
In HTML, colors are represented in two ways. One i...
Table of contents Preface 1. Install Docker 2. In...