Improve vue routing.

This commit is contained in:
Richard Lewis 2019-11-07 16:48:45 +00:00 committed by Pavel Djundik
parent 916da73108
commit d232ef1557

View File

@ -20,10 +20,37 @@ const router = new VueRouter({
name: "SignIn", name: "SignIn",
path: "/sign-in", path: "/sign-in",
component: SignIn, component: SignIn,
beforeEnter(to, from, next) {
// Prevent navigating to sign-in when already signed in
if (store.state.appLoaded) {
next(false);
return;
}
next();
},
}, },
], ],
}); });
router.beforeEach((to, from, next) => {
// Handle closing image viewer with the browser back button
if (!router.app.$refs.app) {
next();
return;
}
const imageViewer = router.app.$root.$refs.app.$refs.imageViewer;
if (imageViewer && imageViewer.link) {
imageViewer.closeViewer();
next(false);
return;
}
next();
});
router.afterEach((to) => { router.afterEach((to) => {
if (store.state.appLoaded) { if (store.state.appLoaded) {
router.app.closeSidebarIfNeeded(); router.app.closeSidebarIfNeeded();