Preface: Sometimes in a route, the main part is the same, but the underlying structure may be different. For example, when you visit the home page, there is The project structure is as follows: We created three components, namely Home.vue <template> <div class="home"> <h1>Home</h1> <router-link to="/home/news">News</router-link> // Note that you must write the full path here. You cannot just write /news. You need to add /home <router-link to="/home/message">Information class</router-link> <router-view></router-view> </div> </template> <script> export default { name: "Home", }; </script> <style scoped> </style> HomeNews <template> <div class="homeNews"> <ul> <li>News 1</li> <li>News 2</li> <li>News 3</li> <li>News 4</li> </ul> </div> </template> <script> export default { name: "HomeNews" } </script> <style scoped> </style> HomeMessage <template> <div class="homeMessage"> <ul> <li>Message 1</li> <li>Message 2</li> <li>Message 3</li> <li>Message 4</li> </ul> </div> </template> <script> export default { name: "HomeMessage" } </script> <style scoped> </style> After the component is written, we configure the route in the import Vue from "vue"; import VueRouter from "vue-router"; Vue.use(VueRouter); // Here we still use routing lazy loading const Home = () => import('../views/Home') const HomeNews = () => import('../views/HomeNews') const HomeMessage = () => import('../views/HomeMessage') const routes = [ { path: "/home", name: "Home", component: Home, // How to write child routes children: [ { path: "news", name: "HomeNews", component: HomeNews }, { path: "message", name: "HomeMessage", component: HomeMessage }, ] }, { path: "", redirect: "home" } ]; const router = new VueRouter({ routes, mode: 'history', }); export default router; Nested routes are very simple to write. You will find that the At this point, based on the above configuration, when you visit This is because no suitable sub-route was matched. If you want to render something, you can provide an empty child route: const routes = [ { path: "/home", name: "Home", component: Home, children: [ { path: "news", name: "HomeNews", component: HomeNews }, { path: "message", name: "HomeMessage", component: HomeMessage }, // Add an empty sub-route { path: "", redirect: "news" } ] }, { path: "", redirect: "home" } ]; In this way, the page will be redirected to the This is the end of this article about vue.js Router nested routing. For more related vue nested routing content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
>>: The best solution for resetting the root password of MySQL 8.0.23
This article uses an example to describe how to u...
Database Command Specification All database objec...
download MySQL official download, select Windows ...
Table of contents 1. Definition of stack 2. JS st...
In MySQL 8.0.18, a new Hash Join function was add...
What to do if you forget your Linux/Mac MySQL pas...
Therefore, we made a selection of 30 combinations ...
This article mainly introduces the solution to th...
What we need to pay attention to is that the char...
If you are using Alibaba Cloud Server, you need t...
In JavaScript's DOM event model, events are r...
A colleague asked me what N and M mean in the MyS...
Table of contents Related dependency installation...
Preface We all know that MySQL query uses the sel...
1. First prepare the MySQL and Eclipse environmen...