zoukankan      html  css  js  c++  java
  • 嵌套路由的坑

    嵌套路由就是路由里面嵌套他的子路由,可以有自己的路由导航和路由容器(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> 

  • 相关阅读:
    Toast的替代者Snackbar
    SnappyDB—Android上的NoSQL数据库简介
    ButterKnife使用小结
    The following classes could not be found:
    asp.net后台解析JSON,并将值赋给对象
    .NET4.0的listview与DataPager的结合使用时的模板编辑
    ASP.NET 后台页面无法识别服务器控件ID
    Asp.net中判断是否是指定页面请求的代码示例
    ASP.NET中修改从数据库获取的datatable中的值
    GridView自定义分页样式(上一页,下一页,到第几页)
  • 原文地址:https://www.cnblogs.com/hy96/p/13121819.html
Copyright © 2011-2022 走看看