如果匹配路径没有匹配到,那么我们就应该跳转到精心制作的没有找到的页面。
当然这个路由的写法是很固定的,我们需要记录一下。
{path:"/:path(.*)",component:notFound}
]
请注意 这里是 正则表达式的写法,记住就好了 /:path(.*)
嵌套路由
所谓嵌套路由其实就是多用了一个children属性
首先我们在父组件里标注位置
<router-link to="/Main/DA" ><h1>去TWo</h1></router-link>
<router-link to="/Main/Two">去大</router-link>
请注意,这里的路径要写上父路由的路径
然后我们要在index.js文件当中完善路由,代码如下
{ path:"/Main",
component :Main,
children:[
{ path:"Two",component:Two},
{path:"DA",component:DA}
]
请注意这里的子组件的path不需要添加 / ,vue会自动添加
js跳转路由,$route表示当前活跃的路由对象,一个 $router表示当前活跃的路由器,有多个
this.$router.push(‘xxx’)里面写路径 或者写带对象 {path: " },并且里面可以带上参数
tiaozhuan(){
this.$router.push("/Two")
}
-----------------------------------------------------------------------------------------------------------------------
重定向 通过 redirect 属性