Skip to content

Commit 3f968e1

Browse files
authored
fix: router plugin baseUrl not work (#6220)
1 parent edb1fea commit 3f968e1

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

.changeset/tender-eyes-occur.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@modern-js/runtime': patch
3+
---
4+
5+
fix: router plugin baseUrl not work
6+
7+
fix: router 插件 baseUrl 不生效

packages/runtime/plugin-router-v5/src/runtime/plugin.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,18 @@ export const routerPlugin = (userConfig: RouterConfig = {}): Plugin => {
165165
const location = getLocation(ssrContext);
166166
const routerContext = ssrContext?.redirection || {};
167167
const request = ssrContext?.request;
168-
const baseUrl = (
169-
runtimeContext._internalRouterBaseName ||
170-
(request?.baseUrl as string)
171-
)?.replace(/^\/*/, '/');
168+
const baseUrl = (request?.baseUrl as string)?.replace(
169+
/^\/*/,
170+
'/',
171+
);
172172

173173
const basename =
174174
baseUrl === '/'
175-
? urlJoin(baseUrl, historyOptions.basename as string)
175+
? urlJoin(
176+
baseUrl,
177+
runtimeContext._internalRouterBaseName ||
178+
(historyOptions.basename as string),
179+
)
176180
: baseUrl;
177181
const runner = (api as any).useHookRunners();
178182
const routes = runner.modifyRoutes(originRoutes);

packages/runtime/plugin-runtime/src/router/runtime/plugin.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,15 @@ export const routerPlugin = (
9292
* basename: modern config file config
9393
*/
9494
const baseUrl = (
95-
runtimeContext._internalRouterBaseName ||
96-
window._SERVER_DATA?.router.baseUrl ||
97-
select(location.pathname)
95+
window._SERVER_DATA?.router.baseUrl || select(location.pathname)
9896
).replace(/^\/*/, '/');
9997
const _basename =
100-
baseUrl === '/' ? urlJoin(baseUrl, basename) : baseUrl;
98+
baseUrl === '/'
99+
? urlJoin(
100+
baseUrl,
101+
runtimeContext._internalRouterBaseName || basename,
102+
)
103+
: baseUrl;
101104

102105
let hydrationData = window._ROUTER_DATA;
103106

0 commit comments

Comments
 (0)