|
@@ -9,8 +9,8 @@ Vue.use(VueRouter);
|
|
|
import Home from '../views/Home.vue';
|
|
|
import My from '../views/My.vue';
|
|
|
import List from '../views/List.vue';
|
|
|
-import Demo1 from '@/components/Demo1.vue';
|
|
|
-import Demo2 from '@/components/Demo2.vue';
|
|
|
+// import Demo1 from '@/components/Demo1.vue';
|
|
|
+// import Demo2 from '@/components/Demo2.vue';
|
|
|
|
|
|
// 2.路由路径
|
|
|
const routes = [
|
|
@@ -22,12 +22,23 @@ const routes = [
|
|
|
{
|
|
|
// 路径
|
|
|
path:"/home",
|
|
|
+ // path:"/home/:name1/:age1",
|
|
|
// 组件页面
|
|
|
- component: Home
|
|
|
+ component: Home,
|
|
|
+ name:"shouye",
|
|
|
+
|
|
|
},
|
|
|
{
|
|
|
path:'/my',
|
|
|
- component: My
|
|
|
+ component: My,
|
|
|
+ name:"wode",
|
|
|
+ beforeEnter:(to,from,next) => {
|
|
|
+ if(localStorage.getItem("user1") === '瑶瑶') {
|
|
|
+ next()
|
|
|
+ } else {
|
|
|
+ alert("充钱")
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
{
|
|
|
path:'/list',
|
|
@@ -39,11 +50,12 @@ const routes = [
|
|
|
},
|
|
|
{
|
|
|
path:'demo1',
|
|
|
- component:Demo1
|
|
|
+ meta:{isAuthor:true,title:"男装"},
|
|
|
+ component:()=>import("../components/Demo1.vue")
|
|
|
},
|
|
|
{
|
|
|
path:'demo2',
|
|
|
- component:Demo2
|
|
|
+ component:()=>import("../components/Demo2.vue")
|
|
|
}
|
|
|
]
|
|
|
}
|
|
@@ -58,4 +70,25 @@ const router = new VueRouter({
|
|
|
routes
|
|
|
})
|
|
|
|
|
|
+// 全局前置路由守卫
|
|
|
+router.beforeEach((to,from,next)=>{
|
|
|
+ // 1.to 目标对象从...来
|
|
|
+ // 2.form 目标对象从...走
|
|
|
+ // 3.next 下一步
|
|
|
+ console.log(to,'to')
|
|
|
+ if(to.meta.isAuthor) {
|
|
|
+ if(localStorage.getItem("user") === '图图') {
|
|
|
+ next()
|
|
|
+ } else {
|
|
|
+ alert("请登录")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ next()
|
|
|
+ }
|
|
|
+})
|
|
|
+// 全局后置路由守卫
|
|
|
+router.afterEach((to,from,next)=>{
|
|
|
+ document.title = to.meta.title || '项目';
|
|
|
+})
|
|
|
+
|
|
|
export default router;
|