Register routes after init

This commit is contained in:
Pavel Djundik 2019-11-03 17:56:41 +02:00
parent aba2487126
commit 2b5a13a043
4 changed files with 42 additions and 24 deletions

View file

@ -2,7 +2,7 @@
<div id="viewport" :class="viewportClasses" role="tablist">
<Sidebar :overlay="$refs.overlay" />
<div id="sidebar-overlay" ref="overlay" @click="$root.setSidebar(false)" />
<article v-if="$root.initialized" id="windows">
<article id="windows">
<router-view></router-view>
</article>
<ImageViewer ref="imageViewer" />

View file

@ -24,6 +24,38 @@ const router = new VueRouter({
windowName: "SignIn",
},
},
],
});
router.afterEach((to) => {
if (!router.app.initialized) {
return;
}
router.app.closeSidebarIfNeeded();
if (!to.meta.isChat) {
// Navigating out of a chat window
store.commit("activeWindow", to.meta.windowName);
if (store.state.activeChannel && store.state.activeChannel.channel) {
router.app.switchOutOfChannel(store.state.activeChannel.channel);
}
store.commit("activeChannel", null);
}
});
function initialize() {
router.addRoutes([
{
path: "/sign-in",
component: SignIn,
meta: {
isChat: false,
windowName: "SignIn",
},
},
{
path: "/connect",
component: Connect,
@ -72,26 +104,10 @@ const router = new VueRouter({
windowName: "RoutedChat",
},
},
],
});
]);
}
router.afterEach((to) => {
if (!router.app.initialized) {
return;
}
router.app.closeSidebarIfNeeded();
if (!to.meta.isChat) {
// Navigating out of a chat window
store.commit("activeWindow", to.meta.windowName);
if (store.state.activeChannel && store.state.activeChannel.channel) {
router.app.switchOutOfChannel(store.state.activeChannel.channel);
}
store.commit("activeChannel", null);
}
});
export default router;
module.exports = {
initialize,
router,
};

View file

@ -8,6 +8,7 @@ const sidebar = $("#sidebar");
const storage = require("../localStorage");
const constants = require("../constants");
const {vueApp, initChannel} = require("../vue");
const router = require("../router");
const store = require("../store").default;
socket.on("init", function(data) {
@ -22,6 +23,7 @@ socket.on("init", function(data) {
store.commit("currentUserVisibleError", null);
if (!vueApp.initialized) {
router.initialize();
vueApp.onSocketInit();
if (data.token) {

View file

@ -9,7 +9,7 @@ const localetime = require("./libs/handlebars/localetime");
const friendlysize = require("./libs/handlebars/friendlysize");
const colorClass = require("./libs/handlebars/colorClass");
const storage = require("./localStorage");
const router = require("./router").default;
const {router} = require("./router");
const constants = require("./constants");
Vue.filter("localetime", localetime);