Skip to content

Commit

Permalink
chore: remove server data parse in convention routes
Browse files Browse the repository at this point in the history
  • Loading branch information
zllkjc committed Dec 20, 2024
1 parent 95b026d commit af76f9e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 35 deletions.
22 changes: 2 additions & 20 deletions packages/runtime/plugin-router-v5/src/runtime/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;
};
};
}
}

export type SingleRouteConfig = RouteProps & {
redirect?: string;
routes?: SingleRouteConfig[];
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
11 changes: 0 additions & 11 deletions packages/runtime/plugin-runtime/src/router/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;
};
};
}
}

export type SingleRouteConfig = RouteProps & {
redirect?: string;
routes?: SingleRouteConfig[];
Expand Down

0 comments on commit af76f9e

Please sign in to comment.