From fb51b9847eb6376567072e2fb2d2742ecbf22069 Mon Sep 17 00:00:00 2001 From: xuchaobei Date: Tue, 18 Jul 2023 18:54:41 +0800 Subject: [PATCH] fix: fix remixRouter not existed in conventional routes (#4240) * fix: fix remixRouter not existed in conventional routes * chore: changeset --- .changeset/ninety-tables-help.md | 6 ++++++ .../plugin-runtime/src/router/runtime/plugin.node.tsx | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .changeset/ninety-tables-help.md diff --git a/.changeset/ninety-tables-help.md b/.changeset/ninety-tables-help.md new file mode 100644 index 000000000000..7061149413b6 --- /dev/null +++ b/.changeset/ninety-tables-help.md @@ -0,0 +1,6 @@ +--- +'@modern-js/runtime': patch +--- + +fix: fix remixRouter not existed in conventional routes +fix: 修复 remixRouter 在约定式路由下不存在问题 diff --git a/packages/runtime/plugin-runtime/src/router/runtime/plugin.node.tsx b/packages/runtime/plugin-runtime/src/router/runtime/plugin.node.tsx index eebd8ba4255d..82cc0719bb98 100644 --- a/packages/runtime/plugin-runtime/src/router/runtime/plugin.node.tsx +++ b/packages/runtime/plugin-runtime/src/router/runtime/plugin.node.tsx @@ -162,11 +162,16 @@ export const routerPlugin = ({ pickContext: ({ context, pickedContext }, next) => { const { remixRouter } = context; + // remixRouter is not existed in conventional routes + if (!remixRouter) { + return next({ context, pickedContext }); + } + // only export partial common API from remix-router const router = { - navigate: remixRouter!.navigate, + navigate: remixRouter.navigate, get location() { - return remixRouter!.state.location; + return remixRouter.state.location; }, };