thelounge/client/js/router.js

83 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-10-17 16:56:44 +00:00
"use strict";
const Vue = require("vue").default;
const VueRouter = require("vue-router").default;
Vue.use(VueRouter);
const store = require("./store").default;
2019-10-17 16:56:44 +00:00
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;
2019-10-17 16:56:44 +00:00
const RoutedChat = require("../components/RoutedChat.vue").default;
const router = new VueRouter({
routes: [
2019-10-20 16:17:21 +00:00
{
2019-11-03 17:09:10 +00:00
name: "SignIn",
2019-10-20 16:17:21 +00:00
path: "/sign-in",
component: SignIn,
},
2019-11-03 15:56:41 +00:00
],
});
router.afterEach((to) => {
2019-11-03 17:09:10 +00:00
if (router.app.initialized) {
router.app.closeSidebarIfNeeded();
2019-11-03 15:56:41 +00:00
}
2019-11-03 17:09:10 +00:00
if (to.name !== "RoutedChat") {
2019-11-03 15:56:41 +00:00
// Navigating out of a chat window
2019-11-03 17:09:10 +00:00
store.commit("activeWindow", to.name);
2019-11-03 15:56:41 +00:00
if (store.state.activeChannel && store.state.activeChannel.channel) {
router.app.switchOutOfChannel(store.state.activeChannel.channel);
}
store.commit("activeChannel", null);
}
});
function initialize() {
router.addRoutes([
{
2019-11-03 17:09:10 +00:00
name: "Connect",
2019-10-20 16:17:21 +00:00
path: "/connect",
component: Connect,
},
{
2019-11-03 17:09:10 +00:00
name: "Settings",
2019-10-20 16:17:21 +00:00
path: "/settings",
component: Settings,
},
{
2019-11-03 17:09:10 +00:00
name: "Help",
2019-10-20 16:17:21 +00:00
path: "/help",
component: Help,
},
{
2019-11-03 17:09:10 +00:00
name: "Changelog",
2019-10-20 16:17:21 +00:00
path: "/changelog",
component: Changelog,
},
{
2019-11-03 17:09:10 +00:00
name: "NetworkEdit",
path: "/edit-network/:uuid",
component: NetworkEdit,
},
2019-10-20 16:17:21 +00:00
{
2019-11-03 17:09:10 +00:00
name: "RoutedChat",
2019-10-20 16:17:21 +00:00
path: "/chan-*",
component: RoutedChat,
},
2019-11-03 15:56:41 +00:00
]);
}
2019-10-20 16:17:21 +00:00
2019-11-03 15:56:41 +00:00
module.exports = {
initialize,
router,
};