import Vue from 'vue'
import VueRouter from "vue-router";
// 作为vue的插件
Vue.use(VueRouter)
import home from "@/components/home";
import about from "@/components/about";
import document from "@/components/document";
import noFound from "@/components/404";;
let router = new VueRouter({
mode: 'history',
linkActiveClass: 'is-active',
routes: [
{
path: '/home',
name: 'Home',
component: home,
alias: '/index' //别名
},{
path: '/about',
name: 'About',
component: about
},{
path: '/document',
name: 'Document',
component: document
},{
path:'*',
redirect: (to)=>{ //动态改变重定向的目标
// 目标路由对象,就是访问的路径的路由信息
if(to.path == '/123'){
return '/home'
}else if(to.path === '/456'){
return {path: '/document'}
}else {
return {name : 'About'}
}
}
// redirect: {name: 'About'}
// redirect: '/home'
// component: noFound
}
]
});
export default router;