sharkey/packages/frontend/src/router/supplier.ts

31 lines
1.0 KiB
TypeScript
Raw Normal View History

/*
* 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 '@/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;
}