Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
xqz
/
dianDemo
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
44277e69
authored
2020-05-31 21:03:29 +0800
by
xiaodi
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
分离路由
1 parent
cd839dc6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
28 deletions
src/config/router.config.js
src/router/index.js
src/config/router.config.js
0 → 100644
View file @
44277e6
/**
* 基础路由
* @type { *[] }
*/
export
const
constantRouterMap
=
[
{
path
:
'/'
,
name
:
'index'
,
component
:
()
=>
import
(
'@/views/home/index'
),
// 路由懒加载
meta
:
{
title
:
'首页'
,
// 页面标题
keepAlive
:
false
// keep-alive 标识
}
},
{
path
:
'/about'
,
name
:
'about'
,
component
:
()
=>
import
(
'@/views/home/about'
),
meta
:
{
title
:
'关于我'
,
keepAlive
:
false
}
}
]
src/router/index.js
View file @
44277e6
import
Vue
from
'vue'
import
Router
from
'vue-router'
import
{
constantRouterMap
}
from
'@/config/router.config'
// hack router push callback
const
originalPush
=
Router
.
prototype
.
push
Router
.
prototype
.
push
=
function
push
(
location
,
onResolve
,
onReject
)
{
if
(
onResolve
||
onReject
)
return
originalPush
.
call
(
this
,
location
,
onResolve
,
onReject
)
return
originalPush
.
call
(
this
,
location
).
catch
(
err
=>
err
)
}
Vue
.
use
(
Router
)
export
const
router
=
[
{
path
:
'/'
,
name
:
'index'
,
component
:
()
=>
import
(
'@/views/home/index'
),
// 路由懒加载
meta
:
{
title
:
'首页'
,
// 页面标题
keepAlive
:
false
// keep-alive 标识
}
},
{
path
:
'/about'
,
name
:
'about'
,
component
:
()
=>
import
(
'@/views/home/about'
),
meta
:
{
title
:
'关于我'
,
keepAlive
:
false
}
}
]
const
createRouter
=
()
=>
new
Router
({
// mode: 'history', // 如果你是 history模式 需要配置vue.config.js publicPath
// base: '/app/',
scrollBehavior
:
()
=>
({
y
:
0
}),
routes
:
router
})
const
createRouter
=
()
=>
new
Router
({
mode
:
'history'
,
base
:
process
.
env
.
BASE_URL
,
scrollBehavior
:
()
=>
({
y
:
0
}),
routes
:
constantRouterMap
})
const
router
=
createRouter
()
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export
function
resetRouter
()
{
const
newRouter
=
createRouter
()
router
.
matcher
=
newRouter
.
matcher
// reset router
}
export
default
createRouter
()
export
default
router
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment