diff --git a/packages/runtime/plugin-router-v5/src/runtime/hooks.ts b/packages/runtime/plugin-router-v5/src/runtime/hooks.ts index 8063b11162e..11861d4af6f 100644 --- a/packages/runtime/plugin-router-v5/src/runtime/hooks.ts +++ b/packages/runtime/plugin-router-v5/src/runtime/hooks.ts @@ -1,8 +1,9 @@ import { createSyncHook } from '@modern-js/plugin-v2'; import type { RouteProps } from 'react-router-dom'; +import type { SingleRouteConfig } from './plugin'; // only for inhouse use const modifyRoutesHook = - createSyncHook<(routes: RouteProps[]) => RouteProps[]>(); + createSyncHook<(routes: RouteProps[]) => SingleRouteConfig[]>(); export { modifyRoutesHook }; diff --git a/packages/runtime/plugin-router-v5/src/runtime/plugin.tsx b/packages/runtime/plugin-router-v5/src/runtime/plugin.tsx index 9b1914faaaa..b7e16d40065 100644 --- a/packages/runtime/plugin-router-v5/src/runtime/plugin.tsx +++ b/packages/runtime/plugin-router-v5/src/runtime/plugin.tsx @@ -63,7 +63,11 @@ let routes: SingleRouteConfig[] = []; export const routerPlugin = ( userConfig: RouterConfig = {}, -): RuntimePluginFuture => { +): RuntimePluginFuture<{ + extendHooks: { + modifyRoutes: typeof modifyRoutesHook; + }; +}> => { return { name: '@modern-js/plugin-router', registryHooks: { @@ -124,8 +128,8 @@ export const routerPlugin = ( (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions)); - const runner = (api as any).useHookRunners(); - routes = runner.modifyRoutes(originRoutes); + const hooks = api.getHooks(); + routes = hooks.modifyRoutes.call(originRoutes); finalRouteConfig && (finalRouteConfig.routes = routes); /** * when exist createRoutes function, App.tsx must be exist, and support Component props @@ -160,8 +164,8 @@ export const routerPlugin = ( (historyOptions.basename as string), ) : baseUrl; - const runner = (api as any).useHookRunners(); - const routes = runner.modifyRoutes(originRoutes); + const hooks = api.getHooks(); + const routes = hooks.modifyRoutes.call(originRoutes); finalRouteConfig && (finalRouteConfig.routes = routes); return (