Skip to content

Commit

Permalink
fix: router v5 unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
caohuilin committed Jan 9, 2025
1 parent efa2993 commit 22ca3b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/runtime/plugin-router-v5/src/runtime/hooks.ts
Original file line number Diff line number Diff line change
@@ -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 };
14 changes: 9 additions & 5 deletions packages/runtime/plugin-router-v5/src/runtime/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 (
<StaticRouter
Expand Down

0 comments on commit 22ca3b2

Please sign in to comment.