forked from JasonBai007/vue-seed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74ee8c2
commit de90f0f
Showing
9 changed files
with
125 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,115 @@ | ||
import Vue from 'vue' | ||
import Router from 'vue-router' | ||
import Vue from "vue"; | ||
import Router from "vue-router"; | ||
|
||
// 登录 | ||
const Signin = resolve => require(['@/views/Signin'], resolve) | ||
const Signin = resolve => require(["@/views/Signin"], resolve); | ||
|
||
// 非登录页的包裹组件 | ||
const Layout = resolve => require(['@/views/Layout'], resolve) | ||
const Layout = resolve => require(["@/views/Layout"], resolve); | ||
|
||
// 项目信息 | ||
const ProjectInfo = resolve => require(['@/views/ProjectInfo'], resolve) | ||
const ProjectInfo = resolve => require(["@/views/ProjectInfo"], resolve); | ||
|
||
// 关于作者 | ||
const About = resolve => require(['@/views/About'], resolve) | ||
const About = resolve => require(["@/views/About"], resolve); | ||
|
||
// 天气预报 | ||
const Weather = resolve => require(['@/views/Weather'], resolve) | ||
// 立方体 | ||
const Cube = resolve => require(['@/views/Cube'], resolve) | ||
// 权限测试 | ||
const AuthorityTest = resolve => require(['@/views/AuthorityTest'], resolve) | ||
// 404 | ||
const Notfound = resolve => require(['@/views/Notfound'], resolve) | ||
const Weather = resolve => require(["@/views/Weather"], resolve); | ||
// 立方体 | ||
const Cube = resolve => require(["@/views/Cube"], resolve); | ||
// 权限测试 | ||
const AuthorityTest = resolve => require(["@/views/AuthorityTest"], resolve); | ||
// 404 | ||
const Notfound = resolve => require(["@/views/Notfound"], resolve); | ||
|
||
Vue.use(Router) | ||
Vue.use(Router); | ||
|
||
const router = new Router({ | ||
routes: [ | ||
// 首先是登录页的路由 | ||
routes: [ | ||
// 首先是登录页的路由 | ||
{ | ||
path: "/signin", | ||
name: "Signin", | ||
meta: { | ||
requireAuth: false, | ||
title: "Auto Vue" | ||
}, | ||
component: Signin | ||
}, | ||
// 然后就是嵌套路由了,也就是登陆后的各个页面 | ||
{ | ||
path: "/", | ||
meta: { | ||
requireAuth: true | ||
}, | ||
component: Layout, | ||
// redirect: '/notes', // 重定向到第一个子路由,否则只渲染Layout组件,这块儿使用时解除注释 | ||
redirect: "/signin", // 这里重定向到登录页面,是为了展示使用,实际用这个项目开发时,需要注释这行,解除上一行的注释 | ||
children: [ | ||
{ | ||
path: '/signin', | ||
name: 'Signin', | ||
meta: { | ||
requireAuth: false | ||
}, | ||
component: Signin | ||
path: "notes", | ||
meta: { | ||
requireAuth: true, | ||
title: "开发备忘" | ||
}, | ||
component: ProjectInfo | ||
}, | ||
// 然后就是嵌套路由了,也就是登陆后的各个页面 | ||
{ | ||
path: '/', | ||
meta: { | ||
requireAuth: true | ||
}, | ||
component: Layout, | ||
// redirect: '/notes', // 重定向到第一个子路由,否则只渲染Layout组件,这块儿使用时解除注释 | ||
redirect: '/signin', // 这里重定向到登录页面,是为了展示使用,实际用这个项目开发时,需要注释这行,解除上一行的注释 | ||
children: [{ | ||
path: 'notes', | ||
meta: { requireAuth: true }, | ||
component: ProjectInfo | ||
}, | ||
{ | ||
path: 'about', | ||
meta: { requireAuth: true }, | ||
component: About | ||
}, | ||
{ | ||
path: 'weather', | ||
meta: { requireAuth: true }, | ||
component: Weather | ||
}, | ||
{ | ||
path: 'cube', | ||
meta: { requireAuth: true }, | ||
component: Cube | ||
}, | ||
{ | ||
path: 'authority', | ||
meta: { requireAuth: true }, | ||
component: AuthorityTest | ||
} | ||
] | ||
path: "about", | ||
meta: { | ||
requireAuth: true, | ||
title: "关于作者" | ||
}, | ||
component: About | ||
}, | ||
// 最后是404页面 | ||
{ | ||
path: '*', | ||
meta: { requireAuth: false }, | ||
component: Notfound | ||
path: "weather", | ||
meta: { | ||
requireAuth: true, | ||
title: "天气预报" | ||
}, | ||
component: Weather | ||
}, | ||
{ | ||
path: "cube", | ||
meta: { | ||
requireAuth: true, | ||
title: "魔幻立方" | ||
}, | ||
component: Cube | ||
}, | ||
{ | ||
path: "authority", | ||
meta: { | ||
requireAuth: true, | ||
title: "权限测试" | ||
}, | ||
component: AuthorityTest | ||
} | ||
] | ||
}) | ||
] | ||
}, | ||
// 最后是404页面 | ||
{ | ||
path: "*", | ||
meta: { | ||
requireAuth: false, | ||
title: "404" | ||
}, | ||
component: Notfound | ||
} | ||
] | ||
}); | ||
|
||
// 当一个导航触发时,全局的 before 钩子按照创建顺序调用。钩子是异步解析执行,此时导航在所有钩子 resolve 完之前一直处于等待中。 | ||
router.beforeEach((to, from, next) => { | ||
// 如果已经登录,并且要去登录页,就不让TA去登录页,重定向到首页 | ||
if (to.path === '/signin' && localStorage.token) { | ||
next('/notes') | ||
} else { | ||
next() | ||
} | ||
}) | ||
// 自动化修改页面标签的 title | ||
document.title = to.meta.title; | ||
// 如果已经登录,并且要去登录页,就不让TA去登录页,重定向到首页 | ||
if (to.path === "/signin" && localStorage.token) { | ||
next("/notes"); | ||
} else { | ||
next(); | ||
} | ||
}); | ||
|
||
export default router | ||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<template> | ||
<div v-title="'关于作者'"> | ||
<div> | ||
关于作者 | ||
<contact-card></contact-card> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<template> | ||
<div class="cube-wrap" v-title="'魔幻立方'"> | ||
<div class="cube-wrap"> | ||
<Cube></Cube> | ||
</div> | ||
</template> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,42 @@ | ||
<template> | ||
<div> | ||
<h1 class="animated flipInX">404</h1> | ||
<div class="back animated bounceInUp"> | ||
<i title="返回" class="fa fa-reply-all" @click="goBack"></i> | ||
</div> | ||
<div> | ||
<h1 class="animated flipInX">404</h1> | ||
<div class="back animated bounceInUp"> | ||
<i title="返回" class="fa fa-reply-all" @click="goBack"></i> | ||
</div> | ||
</div> | ||
</template> | ||
<script> | ||
export default { | ||
name: 'notfound', | ||
methods: { | ||
goBack() { | ||
this.$router.go(-1) | ||
} | ||
name: "notfound", | ||
methods: { | ||
goBack() { | ||
this.$router.go(-1); | ||
} | ||
} | ||
} | ||
}; | ||
</script> | ||
<style scoped lang="scss"> | ||
h1 { | ||
text-align: center; | ||
font-size: 12em; | ||
font-family: fantasy; | ||
color: #475669; | ||
letter-spacing: 25px; | ||
text-align: center; | ||
font-size: 12em; | ||
font-family: fantasy; | ||
color: #475669; | ||
letter-spacing: 25px; | ||
margin-top: 0; | ||
padding-top: 25vh; | ||
} | ||
.back { | ||
padding-right: 3em; | ||
text-align: right; | ||
i { | ||
font-size: 2em; | ||
color: #475669; | ||
&:hover { | ||
cursor: pointer; | ||
color: #324057; | ||
} | ||
padding-right: 3em; | ||
text-align: right; | ||
i { | ||
font-size: 2em; | ||
color: #475669; | ||
&:hover { | ||
cursor: pointer; | ||
color: #324057; | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters