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
1. Basic structure: Copy code The code is as follo...
Horizontal scrolling isn’t appropriate in all situ...
1.Tomcat Optimization Configuration (1) Change To...
Table of contents 【Function Background】 [Raw SQL]...
MyISAM and InnoDB are the most common storage eng...
Table of contents Functionalcomponents Childcompo...
Table of contents Overview 1. Function debounce 2...
Priority The reason why placing the same conditio...
1. Inline elements only occupy the width of the co...
Table of contents Preface Introduction to Session...
When we add borders to table and td tags, double ...
IE's conditional comments are a proprietary (...
Possible solutions 1. Math.random generates rando...
XML/HTML CodeCopy content to clipboard < div s...
Preface I recently learned Linux, and then change...