【问题标题】:Vue router starting route cant be redirectedVue路由器启动路由无法重定向
【发布时间】:2018-04-13 14:59:52
【问题描述】:

我目前遇到的问题是我的 '/' 带有 vue-router 的路由显示一个空白页面。

我的路线是这样的

const route = [
   {
    path: '',
    component: HomeTemplate,
    children: [
     {
      path: '/home', component: Homepage
     }
    ] 
   }
 ]

如何将我的 '''/' 路由重定向到找不到页面的组件

【问题讨论】:

    标签: javascript vue.js vue-router


    【解决方案1】:

    试试这个:

    const route = [
       {
            path: '/home',
            component: Homepage
       },
       {
            // other routes ...
       },
       {
            path: "*",
            component: PageNotFoundComponent
       }
     ]
    

    如果您想将一个组件包装到另一个组件中,请使用 <slot></slot> 元素,请阅读此处:https://vuejs.org/v2/guide/components.html#Content-Distribution-with-Slots

    例子:

    父组件:

    <template>
      <div>
        <!-- Something fun -->
        <slot></slot>
      </div>
    </template>
    
    <script>
    export default {
    
    }
    </script>
    

    子组件:

    <template>
      <parent-component>
        <!-- Something else -->
      </parent-component>
    </template>
    
    <script>
    import ParentComponent from 'path-to-parent-component'
    
    export default {
      components: {ParentComponent}
    }
    </script>
    

    【讨论】:

    • 我必须使用 HomeTemplate。我在那个组件中制作了我的菜单栏/侧边栏
    • 按照我的例子,你可以将Homepage组件包装成HomeTemplate
    猜你喜欢
    • 1970-01-01
    • 2018-04-09
    • 2017-07-21
    • 2020-12-18
    • 2018-06-01
    • 2019-06-28
    • 1970-01-01
    • 2020-07-30
    • 2019-12-05
    相关资源
    最近更新 更多