Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mould-vuecli3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lhfe
mould-vuecli3
Commits
f626eca7
Commit
f626eca7
authored
Sep 01, 2020
by
lipengcheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 优化router.beforeEach鉴权方法
parent
7b7fb5c8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
2 deletions
+4
-2
index.js
src/router/index.js
+1
-2
page1.router.js
src/router/page1.router.js
+3
-0
No files found.
src/router/index.js
View file @
f626eca7
import
Vue
from
'vue'
import
VueRouter
from
'vue-router'
import
store
from
'@/store/index.js'
console
.
log
(
'store:'
,
store
)
Vue
.
use
(
VueRouter
)
...
...
@@ -57,7 +56,7 @@ const router = new VueRouter({
// 路由全局前置守卫
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
if
(
to
.
name
!==
'page2'
&&
!
store
.
getters
[
'authed'
])
next
({
name
:
'page2'
})
if
(
to
.
meta
.
needAuth
&&
!
store
.
getters
[
'authed'
])
next
({
name
:
'page2'
})
else
next
()
})
...
...
src/router/page1.router.js
View file @
f626eca7
export
default
{
path
:
'/page1'
,
name
:
'Page1'
,
meta
:
{
needAuth
:
true
},
component
:
()
=>
import
(
/* webpackChunkName: "page1" */
'../views/page1.vue'
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment