diff --git a/src/router/index.js b/src/router/index.js index 7126661bbe5fce42801e33aaec16ffdd573eb7b2..cc7c23133e1a6289eef9d945a2ddb510fceaffb4 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -4,6 +4,10 @@ import Projects from '../views/Projects.vue'; Vue.use(VueRouter); +//* store initial route before redirect to login page +//* in order to turn back to shared project afterwards (not memorized in router history at page load) +window.initialRoute = window.location.href; + let projectBase = 'projet'; if (window.location.pathname.includes('projet-partage')) { projectBase = 'projet-partage'; @@ -18,10 +22,7 @@ const routes = [ { path: '/connexion/', name: 'login', - // route level code-splitting - // this generates a separate chunk (login.[hash].js) for this route - // which is lazy-loaded when the route is visited. - component: () => import(/* webpackChunkName: "login" */'../views/registration/Login.vue') + component: () => import('../views/registration/Login.vue') }, { path: `${projectBase === 'projet' ? '': '/' + projectBase + '/:slug'}/my_account/`, @@ -137,14 +138,14 @@ const routes = [ { path: '/:pathMatch(.*)*', name: 'NotFound', component: () => import('../views/NotFound.vue') }, ]; -//let routerHistory = []; const router = new VueRouter({ mode: 'history', base: '/geocontrib/', routes, routerHistory: [], - scrollBehavior(to, from, savedPosition) { //* record each route change to turn back to origin after redirect + scrollBehavior(to, from, savedPosition) { //* record each route change to keep scroll position + console.log('scrollBehavior', savedPosition, this.options, this.options.routerHistory); const fromHistory = Boolean(savedPosition); if (fromHistory && this.options.routerHistory.length > 0) { diff --git a/src/store/index.js b/src/store/index.js index 743b1431da014bb91434ae66fbe1eca1e14ffb4e..4631cbb4fd7dd17fe79e391a31767ed1773391e1 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -146,7 +146,13 @@ export default new Vuex.Store({ routerHistory = '/'; } commit('SET_USER', response.data.user); - router.push(routerHistory[routerHistory.length - 1] || '/'); + + if (routerHistory === '/' && window.initialRoute.includes('projet-partage')) { + window.location.replace(window.initialRoute); + } else { // ToDo : not working at page load, routerHistory filled afterwards, could try history.back() + router.push(routerHistory[routerHistory.length - 1] || '/'); + } + dispatch('GET_USER_LEVEL_PROJECTS'); dispatch('GET_USER_LEVEL_PERMISSIONS'); return response.status;