refactor(frontend): router.ts解きほぐし (#12907)

* refactor(frontend): router.ts解きほぐし

* add debug hmr option

* fix comment

* fix not working

* add comment

* fix name

* Update definition.ts

---------

Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
This commit is contained in:
おさむのひと
2024-01-08 14:44:43 +09:00
committed by GitHub
parent 0ed2a220f4
commit 04f9147db6
49 changed files with 937 additions and 650 deletions

View File

@@ -0,0 +1,30 @@
/*
* SPDX-FileCopyrightText: syuilo and other misskey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { inject } from 'vue';
import { IRouter, Router } from '@/nirax.js';
import { mainRouter } from '@/global/router/main.js';
/**
* メインの{@link Router}を取得する。
* あらかじめ{@link setupRouter}を実行しておく必要がある({@link provide}により{@link IRouter}のインスタンスを注入可能であるならばこの限りではない)
*/
export function useRouter(): IRouter {
return inject<Router | null>('router', null) ?? mainRouter;
}
/**
* 任意の{@link Router}を取得するためのファクトリを取得する。
* あらかじめ{@link setupRouter}を実行しておく必要がある。
*/
export function useRouterFactory(): (path: string) => IRouter {
const factory = inject<(path: string) => IRouter>('routerFactory');
if (!factory) {
console.error('routerFactory is not defined.');
throw new Error('routerFactory is not defined.');
}
return factory;
}