Vue路由器启动路由无法重定向

时间:2017-11-01 10:07:34

标签: javascript vue.js vue-router

我目前遇到的问题是我的'/'路由与vue-router显示空页。

我的路线看起来像这样

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

如何将'''/'路由重定向到未找到的网页

1 个答案:

答案 0 :(得分:0)

试试这个:

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>