memories/src/router.ts

140 lines
3.4 KiB
TypeScript
Raw Normal View History

2022-08-16 01:12:14 +00:00
/**
* @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
2022-10-28 19:08:34 +00:00
import { generateUrl } from "@nextcloud/router";
import { translate as t, translatePlural as n } from "@nextcloud/l10n";
import Router from "vue-router";
import Vue from "vue";
import Timeline from "./components/Timeline.vue";
2022-08-16 01:12:14 +00:00
2022-10-28 19:08:34 +00:00
Vue.use(Router);
2022-08-16 01:12:14 +00:00
2022-10-28 19:08:34 +00:00
/**
* Parse the path of a route : join the elements of the array and return a single string with slashes
* + always lead current path with a slash
*
* @param {string | Array} path path arguments to parse
* @return {string}
*/
const parsePathParams = (path) => {
return `/${Array.isArray(path) ? path.join("/") : path || ""}`;
};
2022-08-16 01:12:14 +00:00
2022-10-28 19:08:34 +00:00
export default new Router({
mode: "history",
// if index.php is in the url AND we got this far, then it's working:
// let's keep using index.php in the url
base: generateUrl("/apps/memories"),
linkActiveClass: "active",
routes: [
{
path: "/",
component: Timeline,
name: "timeline",
props: (route) => ({
rootTitle: t("memories", "Timeline"),
}),
},
2022-08-17 20:39:48 +00:00
2022-10-28 19:08:34 +00:00
{
path: "/folders/:path*",
component: Timeline,
name: "folders",
props: (route) => ({
rootTitle: t("memories", "Folders"),
}),
},
2022-09-12 02:21:20 +00:00
2022-10-28 19:08:34 +00:00
{
path: "/favorites",
component: Timeline,
name: "favorites",
props: (route) => ({
rootTitle: t("memories", "Favorites"),
}),
},
2022-09-13 07:55:32 +00:00
2022-10-28 19:08:34 +00:00
{
path: "/videos",
component: Timeline,
name: "videos",
props: (route) => ({
rootTitle: t("memories", "Videos"),
}),
},
2022-09-25 23:02:26 +00:00
2022-10-28 19:08:34 +00:00
{
path: "/albums/:user?/:name?",
component: Timeline,
name: "albums",
props: (route) => ({
rootTitle: t("memories", "Albums"),
}),
},
2022-10-26 22:12:46 +00:00
2022-10-28 19:08:34 +00:00
{
path: "/archive",
component: Timeline,
name: "archive",
props: (route) => ({
rootTitle: t("memories", "Archive"),
}),
},
2022-10-06 20:20:29 +00:00
2022-10-28 19:08:34 +00:00
{
path: "/thisday",
component: Timeline,
name: "thisday",
props: (route) => ({
rootTitle: t("memories", "On this day"),
}),
},
2022-10-06 23:28:35 +00:00
2022-10-28 19:08:34 +00:00
{
path: "/people/:user?/:name?",
component: Timeline,
name: "people",
props: (route) => ({
rootTitle: t("memories", "People"),
}),
},
2022-10-28 19:08:34 +00:00
{
path: "/tags/:name*",
component: Timeline,
name: "tags",
props: (route) => ({
rootTitle: t("memories", "Tags"),
}),
},
2022-10-26 18:58:06 +00:00
2022-10-28 19:08:34 +00:00
{
path: "/maps",
name: "maps",
// router-link doesn't support external url, let's force the redirect
beforeEnter() {
window.open(generateUrl("/apps/maps"), "_blank");
},
},
],
});