dumi
dumi copied to clipboard
怎么配置路由重定向?
在.dumirc.ts里面配置如下代码
import {defineConfig} from 'dumi';
export default defineConfig({
themeConfig: {
name: 'lowcode-platform doc',
nav: [{link: '/guide/intro'}],
},
routes: [{path: '/', redirect: '/guide/intro'}]
});
然后报错:
fatal - TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be o
f type string. Received undefined
at new NodeError (node:internal/errors:393:5)
at validateString (node:internal/validators:163:11)
at Object.resolve (node:path:1098:7)
at /Users/fgui/Work/lowcode-engine-doc/node_modules/dumi/dist/featu
res/routes.js:133:73
at Array.forEach (<anonymous>)
at Hook.fn (/Users/fgui/Work/lowcode-engine-doc/node_modules/dumi/d
ist/features/routes.js:132:27)
at /Users/fgui/Work/lowcode-engine-doc/node_modules/@umijs/core/dis
t/service/service.js:129:38
at _next0 (eval at create (/Users/fgui/Work/lowcode-engine-doc/node
_modules/@umijs/bundler-utils/compiled/tapable/index.js:1:8410), <anony
mous>:51:17)
at eval (eval at create (/Users/fgui/Work/lowcode-engine-doc/node_m
odules/@umijs/bundler-utils/compiled/tapable/index.js:1:8410), <anonymo
us>:75:1)
at process.processTicksAndRejections (node:internal/process/task_qu
eues:95:5) {
code: 'ERR_INVALID_ARG_TYPE'
}
fatal - A complete log of this run can be found in:
fatal - /Users/fgui/Work/lowcode-engine-doc/node_modules/.cache/logger/
umi.log
fatal - Consider reporting a GitHub issue on https://github.com/umijs/u
mi/issues
同问,我也遇到了这个问题,官方文档对于这里的介绍并不多
观察到 最近一个 commit 是做重定向的操作的,添加了 app.tsx 作为运行时去修改 router 的。不知道对你有没有帮助 :)
同问,我也遇到了这个问题,
// @ts-ignore
import { Navigate } from 'dumi';
import React from 'react';
export const patchClientRoutes = ({ routes }: any) => {
/**
* redirect / to /intro
*/
routes[0].children.push({
id: 'root-redirect',
path: '/',
element: <Navigate to="/intro" />,
});
return routes;
};
把首页重定向到intro,我这样写了,还是没有效果,不知道为什么,请问哪里写错了呢
观察到 最近一个 commit 是做重定向的操作的,添加了 app.tsx 作为运行时去修改 router 的。不知道对你有没有帮助 :)
// @ts-ignore import { Navigate } from 'dumi'; import React from 'react'; export const patchClientRoutes = ({ routes }: any) => { /** * redirect / to /intro */ routes[0].children.push({ id: 'root-redirect', path: '/', element: <Navigate to="/intro" />, }); return routes; };
把首页重定向到intro,我这样写了,还是没有效果,不知道为什么,请问哪里写错了呢
观察到 最近一个 commit 是做重定向的操作的,添加了 app.tsx 作为运行时去修改 router 的。不知道对你有没有帮助 :)
抱歉回复的有些晚了, 针对这个问题我在社区看到过好几次了。 这里我给一个我自己的 debug 方案吧。我不是很熟悉 react router 的东西。多数都是猜测的。 在 app 添加一个 patchClientRoutes
方法并且具名导出这没有问题。 我们可以把 routers 通过控制台打印出来。如下图
包括我的 https://github.com/Wxh16144/dumi-debug-app/pull/4 这个 pr 示例也是。
所以你提供的这个代码示例可能需要将 push
改成 unshift
。 不过具体问题还需要具体分析。
// @ts-ignore
import { Navigate } from 'dumi';
import React from 'react';
export const patchClientRoutes = ({ routes }: any) => {
/**
* redirect / to /intro
*/
- routes[0].children.push({
+ routes[0].children.unshift({
id: 'root-redirect',
path: '/',
element: <Navigate to="/intro" />,
});
return routes;
};