嵌套路由的坑
嵌套路由就是路由里面嵌套他的子路由,可以有自己的路由导航和路由容器(router-link、router-view),通过配置children可实现多层嵌套
//mine组件 <template> <div class="content"> 在mine的组件里面嵌套路由 <router-link to="/mine/c">去到Cpage</router-link> <router-link to="/mine/d">去到Dpage</router-link> <div class="child"> <router-view></router-view> </div> </div> </template>
//router.js
//引入需要的组件,下是我的路径
import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/home'
import Mine from '@/components/mine'
import Cpage from '@/page/mine/c'
import Dpage from '@/page/mine/d'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
redirect: 'home'
},
{
path: '/home',
name: 'home',
component: Home
},
{
path: '/mine',
name: 'Mine',
component:Mine,
children:[
{
path:'/',
component:Cpage,
},
{
path:'/mine/c',
component:Cpage,
},
{
path:'/mine/d',
component:Dpage,
}
]
//children这是嵌套的部分
},
//c.vue <template> <div class="top-80"> c.vue <p>这里Cpage文件</p> </div> </template> //d.vue <template> <div class="top-80"> d.vue <p>这里Dpage文件</p> </div> </template>
我所遇到的坑
//route.js const App = () => import('../App.vue'); const Login = () => import('../component/Login.vue'); const Class = () => import('../component/Class.vue'); const CourseList = () => import('../component/CourseList.vue'); const CourseContent = () => import('../component/CourseContent.vue'); const routers = [{ path:'/', component:App, children:[{ path:'login', component:Login },{ path:'class', component:Class }, { path:'course', children:[{ path:'list', component:CourseList },{ path:'content', component:CourseContent } ] }, ] }] export default routers
当你访问的时候,发现
http://localhost:8080/#/login
http://localhost:8080/#/class
都正常,但是:
http://localhost:8080/#/course/list
http://localhost:8080/#/course/content
都是一片空白,检查元素,发现没有加载过来。检查,子路由前面并没有加/,所以这没有问题,排除。
其实这是list的父级course没有component,有了componnet,并且需要在这个component里面要有<router-view></router-view>
长风破浪会有时,直挂云帆济沧海
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!