Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
so-manage-ui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
smart-operation
so-manage-ui
Commits
f9a2760f
Commit
f9a2760f
authored
Jun 21, 2023
by
李鹏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mofigy
parent
036e934a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
109 deletions
+54
-109
src/router/index.js
src/router/index.js
+54
-109
No files found.
src/router/index.js
View file @
f9a2760f
...
@@ -3,44 +3,8 @@
...
@@ -3,44 +3,8 @@
import
{
createRouter
,
createWebHashHistory
}
from
"
vue-router
"
;
import
{
createRouter
,
createWebHashHistory
}
from
"
vue-router
"
;
import
store
from
"
../store
"
;
import
store
from
"
../store
"
;
//写入初始必须有的路由
//写入初始必须有的路由
//或者隐藏式路由,不会表现在菜单上,但是需要存在的路由
//或者隐藏式路由,不会表现在菜单上,但是需要存在的路由
<<<<<<<
Updated
upstream
const
routes
=
[{
path
:
"
/login
"
,
name
:
"
login
"
,
show
:
true
,
component
:
()
=>
import
(
"
../page/login/index.vue
"
),
},
{
path
:
"
/register
"
,
name
:
"
register
"
,
show
:
true
,
component
:
()
=>
import
(
"
../page/register/index.vue
"
),
},
{
path
:
"
/password
"
,
name
:
"
password
"
,
show
:
true
,
component
:
()
=>
import
(
"
../page/password/index.vue
"
),
},
{
path
:
"
/
"
,
name
:
"
index
"
,
component
:
()
=>
import
(
"
../page/welcom.vue
"
),
},
{
path
:
"
/404
"
,
show
:
true
,
component
:
()
=>
import
(
"
../page/404.vue
"
),
},
=======
const
routes
=
[
const
routes
=
[
{
{
path
:
"
/login
"
,
path
:
"
/login
"
,
...
@@ -64,73 +28,59 @@ const routes = [
...
@@ -64,73 +28,59 @@ const routes = [
show
:
true
,
show
:
true
,
component
:
()
=>
import
(
"
../page/404.vue
"
),
component
:
()
=>
import
(
"
../page/404.vue
"
),
},
},
>>>>>>>
Stashed
changes
];
];
//重新创建router
//重新创建router
function
newRouterFunc
()
{
function
newRouterFunc
()
{
return
createRouter
({
return
createRouter
({
history
:
createWebHashHistory
(),
history
:
createWebHashHistory
(),
routes
,
routes
,
});
});
}
}
const
router
=
newRouterFunc
();
const
router
=
newRouterFunc
();
function
inWhiteList
(
toPath
)
{
function
inWhiteList
(
toPath
)
{
//配置白名单
//配置白名单
const
whiteList
=
[
'
/login
'
]
const
whiteList
=
[
"
/login
"
];
const
path
=
whiteList
.
find
((
value
)
=>
{
const
path
=
whiteList
.
find
((
value
)
=>
{
// 使用正则匹配
// 使用正则匹配
const
reg
=
new
RegExp
(
'
^
'
+
value
)
const
reg
=
new
RegExp
(
"
^
"
+
value
);
return
reg
.
test
(
toPath
)
return
reg
.
test
(
toPath
);
})
});
return
!!
path
return
!!
path
;
}
}
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
<<<<<<<
Updated
upstream
=======
const
userInfo
=
store
.
state
.
userInfo
;
const
userInfo
=
store
.
state
.
userInfo
;
//已登录不可跳转登陆页 || to.path == "/" 去除首页跳转判断
//已登录不可跳转登陆页
if
(
userInfo
&&
to
.
path
==
"
/login
"
)
{
if
(
userInfo
&&
to
.
path
==
"
/login
"
)
{
return
next
({
next
({
path
:
from
.
path
});
path
:
"
/
"
,
});
}
}
>>>>>>>
Stashed
changes
const
userInfo
=
store
.
state
.
userInfo
//已登录不可跳转登陆页
if
(
userInfo
&&
to
.
path
==
'
/login
'
)
{
next
({
path
:
from
.
path
})
}
// 检查to.path是否存在于免登陆白名单
// 检查to.path是否存在于免登陆白名单
if
(
inWhiteList
(
to
.
path
))
{
if
(
inWhiteList
(
to
.
path
))
{
next
()
next
();
}
else
{
}
else
{
// 判断是否已经登录,未登录则重定向到首页或其他页面(通过query传参记录原来的路径)
// 判断是否已经登录,未登录则重定向到首页或其他页面(通过query传参记录原来的路径)
// 根据配置判断是否跳转第三方登录,跳转第三方登录则不跳login
// 根据配置判断是否跳转第三方登录,跳转第三方登录则不跳login
// axios封装中也需要对是否登录过期进行判断,如果登录过期,则跳转登录页,具体跳转地址根据配置来·
// axios封装中也需要对是否登录过期进行判断,如果登录过期,则跳转登录页,具体跳转地址根据配置来·
// if (!userInfo) {
// if (!userInfo) {
// next({
// next({
// path: '/login',
// path: '/login',
// })
// })
// } else {
// } else {
// }
// }
}
}
//判读是否匹配,否则跳转404
if
(
to
.
matched
.
length
!==
0
)
{
next
()
}
else
{
return
next
({
path
:
'
/404
'
})
}
})
//判读是否匹配,否则跳转404
if
(
to
.
matched
.
length
!==
0
)
{
next
();
}
else
{
return
next
({
path
:
"
/404
"
});
}
});
// 在路由完成初始导航时调用,如果有异步操作放置到这里
// 在路由完成初始导航时调用,如果有异步操作放置到这里
// 请求相应的角色和菜单
// 请求相应的角色和菜单
...
@@ -138,38 +88,33 @@ router.beforeEach((to, from, next) => {
...
@@ -138,38 +88,33 @@ router.beforeEach((to, from, next) => {
// generateRoutes()
// generateRoutes()
// })
// })
function
addRoute
(
router
,
routers
)
{
function
addRoute
(
router
,
routers
)
{
routers
.
forEach
(
e
=>
{
routers
.
forEach
((
e
)
=>
{
router
.
addRoute
(
e
)
router
.
addRoute
(
e
);
if
(
e
.
children
&&
e
.
children
.
length
)
{
if
(
e
.
children
&&
e
.
children
.
length
)
{
addRoute
(
router
,
e
.
children
)
addRoute
(
router
,
e
.
children
);
}
}
});
});
}
}
export
function
generateRoutes
()
{
export
function
generateRoutes
()
{
const
_asyncRoutes
=
store
.
state
.
route
const
_asyncRoutes
=
store
.
state
.
route
;
if
(
_asyncRoutes
)
{
//动态添加路由
addRoute
(
router
,
_asyncRoutes
)
}
router
.
addRoute
({
if
(
_asyncRoutes
)
{
path
:
'
/:pathMatch(.*)
'
,
//动态添加路由
redirect
:
'
/404
'
})
addRoute
(
router
,
_asyncRoutes
);
}
router
.
addRoute
({
path
:
"
/:pathMatch(.*)
"
,
redirect
:
"
/404
"
,
});
}
}
//新创建一个router替代之前的router,并把matcher方法替换成新的router的matcher
//新创建一个router替代之前的router,并把matcher方法替换成新的router的matcher
export
function
resetRouter
()
{
export
function
resetRouter
()
{
const
newRouter
=
newRouterFunc
()
const
newRouter
=
newRouterFunc
();
router
.
matcher
=
newRouter
.
matcher
router
.
matcher
=
newRouter
.
matcher
;
}
}
export
default
router
;
export
default
router
\ No newline at end of file
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