Skip to content

Commit

Permalink
feat(ui): restore last route
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Apr 17, 2018
1 parent f79cb6e commit 65019d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions packages/@vue/cli-ui/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ const app = new Vue({

async function start () {
app.$mount('#app')

// Restore last route
const lastRoute = localStorage.getItem('vue-cli-ui.lastRoute')
if (lastRoute) {
router.push(lastRoute)
}
}

start()
21 changes: 18 additions & 3 deletions packages/@vue/cli-ui/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const router = new Router({
path: '/',
component: ProjectHome,
meta: {
needProject: true
needProject: true,
restore: true
},
children: [
{
Expand Down Expand Up @@ -75,12 +76,18 @@ const router = new Router({
{
path: '/project/select',
name: 'project-select',
component: ProjectSelect
component: ProjectSelect,
meta: {
restore: true
}
},
{
path: '/project/create',
name: 'project-create',
component: ProjectCreate
component: ProjectCreate,
meta: {
restore: true
}
},
{
path: '/file-diff',
Expand Down Expand Up @@ -119,4 +126,12 @@ router.beforeEach(async (to, from, next) => {
next()
})

router.afterEach((to, from) => {
if (to.matched.some(m => m.meta.restore)) {
localStorage.setItem('vue-cli-ui.lastRoute', to.fullPath)
} else {
localStorage.removeItem('vue-cli-ui.lastRoute')
}
})

export default router

0 comments on commit 65019d6

Please sign in to comment.