From af76f9e616101b09c177f35c53926123bb4c43cf Mon Sep 17 00:00:00 2001 From: kongjiacong Date: Fri, 20 Dec 2024 17:53:47 +0800 Subject: [PATCH] chore: remove server data parse in convention routes --- .../plugin-router-v5/src/runtime/plugin.tsx | 22 ++----------------- .../src/router/runtime/plugin.tsx | 5 +---- .../src/router/runtime/types.ts | 11 ---------- 3 files changed, 3 insertions(+), 35 deletions(-) diff --git a/packages/runtime/plugin-router-v5/src/runtime/plugin.tsx b/packages/runtime/plugin-router-v5/src/runtime/plugin.tsx index 4c01bb9f029..eeb63748391 100644 --- a/packages/runtime/plugin-router-v5/src/runtime/plugin.tsx +++ b/packages/runtime/plugin-router-v5/src/runtime/plugin.tsx @@ -23,17 +23,6 @@ import { import { modifyRoutesHook } from './hooks'; import { getLocation, renderRoutes, urlJoin } from './utils'; -declare global { - interface Window { - _SERVER_DATA?: { - router: { - baseUrl: string; - params: Record; - }; - }; - } -} - export type SingleRouteConfig = RouteProps & { redirect?: string; routes?: SingleRouteConfig[]; @@ -115,19 +104,12 @@ export const routerPlugin = (userConfig: RouterConfig = {}): Plugin => { const select = (pathname: string) => serverBase.find(baseUrl => pathname.search(baseUrl) === 0) || '/'; - if (isBrow) { - window._SERVER_DATA = parsedJSONFromElement( - '__MODERN_SERVER_DATA__', - ); - } + const getRouteApp = () => { if (isBrow) { return (props: any) => { const runtimeContext = useContext(RuntimeReactContext); - const baseUrl = ( - window._SERVER_DATA?.router.baseUrl || - select(location.pathname) - ).replace(/^\/*/, '/'); + const baseUrl = select(location.pathname).replace(/^\/*/, '/'); const basename = baseUrl === '/' ? urlJoin( diff --git a/packages/runtime/plugin-runtime/src/router/runtime/plugin.tsx b/packages/runtime/plugin-runtime/src/router/runtime/plugin.tsx index f6d9cac72b5..c5ec6f0c02b 100644 --- a/packages/runtime/plugin-runtime/src/router/runtime/plugin.tsx +++ b/packages/runtime/plugin-runtime/src/router/runtime/plugin.tsx @@ -47,7 +47,6 @@ export const routerPlugin = ( }, setup: api => { let routes: RouteObject[] = []; - window._SERVER_DATA = parsedJSONFromElement('__MODERN_SERVER_DATA__'); return { beforeRender(context) { // for garfish plugin to get basename, @@ -98,9 +97,7 @@ export const routerPlugin = ( * _internalRouterBaseName: garfish plugin params, priority * basename: modern config file config */ - const baseUrl = ( - window._SERVER_DATA?.router.baseUrl || select(location.pathname) - ).replace(/^\/*/, '/'); + const baseUrl = select(location.pathname).replace(/^\/*/, '/'); const _basename = baseUrl === '/' ? urlJoin( diff --git a/packages/runtime/plugin-runtime/src/router/runtime/types.ts b/packages/runtime/plugin-runtime/src/router/runtime/types.ts index 25f7bc7d797..a715d670069 100644 --- a/packages/runtime/plugin-runtime/src/router/runtime/types.ts +++ b/packages/runtime/plugin-runtime/src/router/runtime/types.ts @@ -6,17 +6,6 @@ import type { } from '@modern-js/runtime-utils/router'; import type { NestedRoute, PageRoute } from '@modern-js/types'; -declare global { - interface Window { - _SERVER_DATA?: { - router: { - baseUrl: string; - params: Record; - }; - }; - } -} - export type SingleRouteConfig = RouteProps & { redirect?: string; routes?: SingleRouteConfig[];