mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-03 18:26:13 +02:00
refactor(frontend): router refactoring
This commit is contained in:
@@ -13,8 +13,8 @@ import { DI } from '@/di.js';
|
||||
|
||||
export type Router = Nirax<typeof ROUTE_DEF>;
|
||||
|
||||
export function createRouter(path: string): Router {
|
||||
return new Nirax(ROUTE_DEF, path, !!$i, page(() => import('@/pages/not-found.vue')));
|
||||
export function createRouter(fullPath: string): Router {
|
||||
return new Nirax(ROUTE_DEF, fullPath, !!$i, page(() => import('@/pages/not-found.vue')));
|
||||
}
|
||||
|
||||
export const mainRouter = createRouter(location.pathname + location.search + location.hash);
|
||||
@@ -24,23 +24,23 @@ window.addEventListener('popstate', (event) => {
|
||||
});
|
||||
|
||||
mainRouter.addListener('push', ctx => {
|
||||
window.history.pushState({ }, '', ctx.path);
|
||||
window.history.pushState({ }, '', ctx.fullPath);
|
||||
});
|
||||
|
||||
mainRouter.addListener('replace', ctx => {
|
||||
window.history.replaceState({ }, '', ctx.path);
|
||||
window.history.replaceState({ }, '', ctx.fullPath);
|
||||
});
|
||||
|
||||
mainRouter.addListener('change', ctx => {
|
||||
console.log('mainRouter: change', ctx.path);
|
||||
console.log('mainRouter: change', ctx.fullPath);
|
||||
analytics.page({
|
||||
path: ctx.path,
|
||||
title: ctx.path,
|
||||
path: ctx.fullPath,
|
||||
title: ctx.fullPath,
|
||||
});
|
||||
});
|
||||
|
||||
mainRouter.init();
|
||||
|
||||
export function useRouter(): Router {
|
||||
return inject(DI.router, null) ?? mainRouter;
|
||||
return inject(DI.router) ?? mainRouter;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user