thelounge/client/js/router.js
Pavel Djundik 2f635069e0 Move vuex state to a separate file and reorganize some code
Co-Authored-By: Tim Miller-Williams <timmw@users.noreply.github.com>
2019-11-25 20:12:54 +02:00

97 lines
1.9 KiB
JavaScript

"use strict";
const Vue = require("vue").default;
const VueRouter = require("vue-router").default;
Vue.use(VueRouter);
const store = require("./store").default;
const SignIn = require("../components/Windows/SignIn.vue").default;
const Connect = require("../components/Windows/Connect.vue").default;
const Settings = require("../components/Windows/Settings.vue").default;
const Help = require("../components/Windows/Help.vue").default;
const Changelog = require("../components/Windows/Changelog.vue").default;
const NetworkEdit = require("../components/Windows/NetworkEdit.vue").default;
const RoutedChat = require("../components/RoutedChat.vue").default;
const router = new VueRouter({
routes: [
{
path: "/sign-in",
component: SignIn,
meta: {
isChat: false,
windowName: "SignIn",
},
},
{
path: "/connect",
component: Connect,
meta: {
isChat: false,
windowName: "Connect",
},
},
{
path: "/settings",
component: Settings,
meta: {
isChat: false,
windowName: "Settings",
},
},
{
path: "/help",
component: Help,
meta: {
isChat: false,
windowName: "Help",
},
},
{
path: "/changelog",
component: Changelog,
meta: {
isChat: false,
windowName: "Changelog",
},
},
{
path: "/edit-network/:uuid",
component: NetworkEdit,
meta: {
isChat: false,
windowName: "NetworkEdit",
},
},
{
path: "/chan-*",
component: RoutedChat,
meta: {
isChat: true,
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;