blob: a944c0e60bc009eeea128477228d35786cbbb410 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { inject } from 'vue';
import { page } from '@/router.definition.js';
import { $i } from '@/i.js';
import { Nirax } from '@/lib/nirax.js';
import { ROUTE_DEF } from '@/router.definition.js';
import { DI } from '@/di.js';
export type Router = Nirax<typeof ROUTE_DEF>;
export function createRouter(fullPath: string): Router {
return new Nirax(ROUTE_DEF, fullPath, !!$i, page(() => import('@/pages/not-found.vue')));
}
export const mainRouter = createRouter(window.location.pathname + window.location.search + window.location.hash);
window.addEventListener('popstate', (event) => {
mainRouter.replace(window.location.pathname + window.location.search + window.location.hash);
});
mainRouter.addListener('push', ctx => {
window.history.pushState({ }, '', ctx.fullPath);
});
mainRouter.addListener('replace', ctx => {
window.history.replaceState({ }, '', ctx.fullPath);
});
mainRouter.init();
export function useRouter(): Router {
return inject(DI.router, null) ?? mainRouter;
}
|