Register routes after init
This commit is contained in:
parent
aba2487126
commit
2b5a13a043
@ -2,7 +2,7 @@
|
|||||||
<div id="viewport" :class="viewportClasses" role="tablist">
|
<div id="viewport" :class="viewportClasses" role="tablist">
|
||||||
<Sidebar :overlay="$refs.overlay" />
|
<Sidebar :overlay="$refs.overlay" />
|
||||||
<div id="sidebar-overlay" ref="overlay" @click="$root.setSidebar(false)" />
|
<div id="sidebar-overlay" ref="overlay" @click="$root.setSidebar(false)" />
|
||||||
<article v-if="$root.initialized" id="windows">
|
<article id="windows">
|
||||||
<router-view></router-view>
|
<router-view></router-view>
|
||||||
</article>
|
</article>
|
||||||
<ImageViewer ref="imageViewer" />
|
<ImageViewer ref="imageViewer" />
|
||||||
|
@ -24,6 +24,38 @@ const router = new VueRouter({
|
|||||||
windowName: "SignIn",
|
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",
|
path: "/connect",
|
||||||
component: Connect,
|
component: Connect,
|
||||||
@ -72,26 +104,10 @@ const router = new VueRouter({
|
|||||||
windowName: "RoutedChat",
|
windowName: "RoutedChat",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
]);
|
||||||
});
|
}
|
||||||
|
|
||||||
router.afterEach((to) => {
|
module.exports = {
|
||||||
if (!router.app.initialized) {
|
initialize,
|
||||||
return;
|
router,
|
||||||
}
|
};
|
||||||
|
|
||||||
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;
|
|
||||||
|
@ -8,6 +8,7 @@ const sidebar = $("#sidebar");
|
|||||||
const storage = require("../localStorage");
|
const storage = require("../localStorage");
|
||||||
const constants = require("../constants");
|
const constants = require("../constants");
|
||||||
const {vueApp, initChannel} = require("../vue");
|
const {vueApp, initChannel} = require("../vue");
|
||||||
|
const router = require("../router");
|
||||||
const store = require("../store").default;
|
const store = require("../store").default;
|
||||||
|
|
||||||
socket.on("init", function(data) {
|
socket.on("init", function(data) {
|
||||||
@ -22,6 +23,7 @@ socket.on("init", function(data) {
|
|||||||
store.commit("currentUserVisibleError", null);
|
store.commit("currentUserVisibleError", null);
|
||||||
|
|
||||||
if (!vueApp.initialized) {
|
if (!vueApp.initialized) {
|
||||||
|
router.initialize();
|
||||||
vueApp.onSocketInit();
|
vueApp.onSocketInit();
|
||||||
|
|
||||||
if (data.token) {
|
if (data.token) {
|
||||||
|
@ -9,7 +9,7 @@ const localetime = require("./libs/handlebars/localetime");
|
|||||||
const friendlysize = require("./libs/handlebars/friendlysize");
|
const friendlysize = require("./libs/handlebars/friendlysize");
|
||||||
const colorClass = require("./libs/handlebars/colorClass");
|
const colorClass = require("./libs/handlebars/colorClass");
|
||||||
const storage = require("./localStorage");
|
const storage = require("./localStorage");
|
||||||
const router = require("./router").default;
|
const {router} = require("./router");
|
||||||
const constants = require("./constants");
|
const constants = require("./constants");
|
||||||
|
|
||||||
Vue.filter("localetime", localetime);
|
Vue.filter("localetime", localetime);
|
||||||
|
Loading…
Reference in New Issue
Block a user