Skip to content

Commit

Permalink
#9 Implement base routing system
Browse files Browse the repository at this point in the history
  • Loading branch information
jofaval committed Jul 23, 2022
1 parent 9d6d99f commit 1cd148e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
7 changes: 7 additions & 0 deletions app/src/router/__tests__/router.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { describe, expect, it } from 'vitest';

describe('Router', () => {
it('should something', () => {
expect(true).toBeTruthy();
});
});
4 changes: 4 additions & 0 deletions app/src/router/constants/routes.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export default {
name: 'fallback',
component: Home,
},
{
path: '*',
redirect: 'home',
},
],
TITLES: {
[pathConstants.HOME]: 'Home',
Expand Down
18 changes: 2 additions & 16 deletions app/src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
// Vendors
import { createRouter, createWebHashHistory } from 'vue-router';
// Constants
import constants from './constants/routes.constants';
import { configConstants } from '../constants';

const router = createRouter({
history: createWebHashHistory(),
routes: constants.ROUTES,
});

router.afterEach((to, from, failure) => {
const toAsString = to.toString();
document.title =
toAsString in constants.TITLES ? constants.TITLES[toAsString] : configConstants.APP_NAME;
});
// Router
import router from './router';

export default router;
18 changes: 18 additions & 0 deletions app/src/router/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Vendors
import { createRouter, createWebHashHistory, RouteLocationNormalized } from 'vue-router';
// Constants
import constants from './constants/routes.constants';
import { configConstants } from '../constants';

const router = createRouter({
history: createWebHashHistory(),
routes: constants.ROUTES,
});

export const onRouteChange = (to: RouteLocationNormalized): void => {
document.title = constants.TITLES?.[to.name?.toString() ?? ''] ?? configConstants.APP_NAME;
};

router.afterEach(onRouteChange);

export default router;

0 comments on commit 1cd148e

Please sign in to comment.