chore: migrate router to TypeScript
Added type annotations to router module and updated it to .ts.
This commit is contained in:
1 file changed
+12
-5
@@ -21,9 +21,14 @@ import SettingsView from '@/features/settings/views/SettingsView.vue';
|
|||||||
import NotFound from '@/views/NotFound.vue';
|
import NotFound from '@/views/NotFound.vue';
|
||||||
|
|
||||||
import { i18n } from '@/i18n';
|
import { i18n } from '@/i18n';
|
||||||
import { createRouter, createWebHistory } from 'vue-router';
|
import {
|
||||||
|
createRouter,
|
||||||
|
createWebHistory,
|
||||||
|
type RouteLocationNormalizedLoaded,
|
||||||
|
type RouteRecordRaw,
|
||||||
|
} from 'vue-router';
|
||||||
|
|
||||||
const routes = [
|
const routes: RouteRecordRaw[] = [
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
name: 'startPage',
|
name: 'startPage',
|
||||||
@@ -37,7 +42,7 @@ const routes = [
|
|||||||
searchQuery: route.query.q,
|
searchQuery: route.query.q,
|
||||||
}),
|
}),
|
||||||
meta: {
|
meta: {
|
||||||
title: (route) => route.query.q,
|
title: (route: RouteLocationNormalizedLoaded) => route.query.q,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -68,7 +73,9 @@ const router = createRouter({
|
|||||||
routes,
|
routes,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const updatePageTitle = function updatePageTitle(route) {
|
export const updatePageTitle = function updatePageTitle(
|
||||||
|
route: RouteLocationNormalizedLoaded,
|
||||||
|
): void {
|
||||||
const title =
|
const title =
|
||||||
typeof route.meta.title === 'function'
|
typeof route.meta.title === 'function'
|
||||||
? route.meta.title(route)
|
? route.meta.title(route)
|
||||||
@@ -82,7 +89,7 @@ export const updatePageTitle = function updatePageTitle(route) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// remove trailing slash(es)
|
// remove trailing slash(es)
|
||||||
router.beforeEach((route) => {
|
router.beforeEach((route: RouteLocationNormalizedLoaded) => {
|
||||||
if (route.path !== '/' && route.path.endsWith('/')) {
|
if (route.path !== '/' && route.path.endsWith('/')) {
|
||||||
return {
|
return {
|
||||||
path: route.path.replace(/\/+$/, ''),
|
path: route.path.replace(/\/+$/, ''),
|
||||||
Reference in new issue
Block a user