Skip to content

Commit 65019d6

Browse files
author
Guillaume Chau
committed
feat(ui): restore last route
1 parent f79cb6e commit 65019d6

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

packages/@vue/cli-ui/src/main.js

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ const app = new Vue({
5454

5555
async function start () {
5656
app.$mount('#app')
57+
58+
// Restore last route
59+
const lastRoute = localStorage.getItem('vue-cli-ui.lastRoute')
60+
if (lastRoute) {
61+
router.push(lastRoute)
62+
}
5763
}
5864

5965
start()

packages/@vue/cli-ui/src/router.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const router = new Router({
2626
path: '/',
2727
component: ProjectHome,
2828
meta: {
29-
needProject: true
29+
needProject: true,
30+
restore: true
3031
},
3132
children: [
3233
{
@@ -75,12 +76,18 @@ const router = new Router({
7576
{
7677
path: '/project/select',
7778
name: 'project-select',
78-
component: ProjectSelect
79+
component: ProjectSelect,
80+
meta: {
81+
restore: true
82+
}
7983
},
8084
{
8185
path: '/project/create',
8286
name: 'project-create',
83-
component: ProjectCreate
87+
component: ProjectCreate,
88+
meta: {
89+
restore: true
90+
}
8491
},
8592
{
8693
path: '/file-diff',
@@ -119,4 +126,12 @@ router.beforeEach(async (to, from, next) => {
119126
next()
120127
})
121128

129+
router.afterEach((to, from) => {
130+
if (to.matched.some(m => m.meta.restore)) {
131+
localStorage.setItem('vue-cli-ui.lastRoute', to.fullPath)
132+
} else {
133+
localStorage.removeItem('vue-cli-ui.lastRoute')
134+
}
135+
})
136+
122137
export default router

0 commit comments

Comments
 (0)