New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
配置路由,开启layout,路由配置3层,页面不渲染 #5221
Comments
很明显umi这种配置形式是不能嵌套子页面的。 {
path: "/access/role",
name: "role",
// component: "./access/role/index", // 删除这个。
routes: [
{
path: "/access/role/detail",
name: "detail",
component: "./access/role/detail/index",
menu: false
}
]
} 当父级被react-router匹配到就会直接渲染,如果想要嵌套你必须自己写Route(react-router) import Detail from './detail'
export default () => {
return (
<>
<Link to="/access/role/detail">Click</Link>
{/* 添加 */}
<Route path="/access/role/detail" component={Detail} />
</>
)
}; |
那其实这个还是解决不了,你想想/access 下面有很多的子页面,/access/role下面的也有很多子页面,这种配置就不行。 另外,像页面的breadcrumb也是直接渲染父组件的breadcrumbName,就不会再往下面查找。 |
我也遇到了同样的问题 |
这个似乎可以解决问题。
|
貌似可以通过运行时配置解决嵌套路由菜单 export const layout = {
logout: () => {
console.log('1234');
}, // do something
menuDataRender:() =>[ //此功能可以实现动态路由,用来渲染访问路由
{
path: '/',
name: '路由模块1',
},
{
path: '/',
name: '路由模块2',
children: [
{ path: '/index1', name: '路由模块2-1' },
{ path: '/user', name: '路由模块2-2' },
],
},
],
// rightRender: initInfo => {
// console.log('initInfo', initInfo);
// return <div>{initInfo.name}</div>;
// }, // return string || ReactNode;
}; |
@wangyuan0108 这个不是问路由菜单的问题 |
我也遇到了这个问题 我还以为是哪里写错了 想着照葫芦画瓢。。。 |
It's inactive above 3 months, feel free to reopen if still have problems. |
@sorrycc 大佬我也遇到了这个3层路由不渲染的问题:
最里面的那一层
|
@kisoua 你这个问题解决了没有呢?感觉可以把这个issue reopen一下 |
@SilentFlute 可以提个新的,给复现。 |
遇到了同样的问题 三层路由不能用 |
遇到了同样的问题 |
现在这个问题解决了嘛?还是不行配置,这个感觉是很基础的功能呀。还有面包屑点击事件怎么能拿到呀 |
哪里不行 你可以在模块里面打debugger 看看有没有进去 |
无法渲染第三层路由页面。路由跳转了,页面显示空白。也没有任何报错 |
你可以贴一下 简单的代码 看看 |
export default [
{
path: '/boundaryandcraft',
component: './_layout',
name: '边界及工艺管理',
icon: 'icon-system',
access: 'adminRouteFilter',
code: 'borderAndCraft',
routes: [
{
path: '/boundaryandcraft/carft',
name: '工艺工序设置',
component: './BoundaryAndCraft/Craft',
exact: true,
routes: [
{
path: '/boundaryandcraft/carft/editbase',
name: '工艺流程设置',
hideInMenu: true,
exact: true,
component: './BoundaryAndCraft/Craft/EditBase',
},
],
},
// {
// path: '/boundaryandcraft/carft/editbase',
// name: '工艺流程设置',
// hideInMenu: true,
// exact: true,
// component: './BoundaryAndCraft/Craft/EditBase',
// },
],
},
]; |
BoundaryAndCraft/Craft 这个模块里面有加下面这个吗 |
没有。那这样的话一个页面好处理。下面模块多了的话不就很麻烦么?配置个路由要改两个地方 |
我是这么解决的 你可以自己本地 打debugger 测试下 如果不用这个方法 欢迎提供另外的方法 |
好的谢谢了。我也想找个更好的方法来解决这个问题 |
欢迎回来二次交流
…------------------ 原始邮件 ------------------
发件人: "umijs/umi" ***@***.***>;
发送时间: 2021年8月30日(星期一) 中午11:07
***@***.***>;
***@***.******@***.******@***.***>;
主题: Re: [umijs/umi] 配置路由,开启layout,路由配置3层,页面不渲染 (#5221)
BoundaryAndCraft/Craft 这个模块里面有加下面这个吗
if ( ['/boundaryandcraft/carft/editbase',].includes(history.location.pathname) ) { return props.children }
没有。那这样的话一个页面好处理。下面模块多了的话不就很麻烦么?配置个路由要改两个地方
我是这么解决的 你可以自己本地 打debugger 测试下 如果不用这个方法 欢迎提供另外的方法
好的谢谢了。我也想找个更好的方法来解决这个问题
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
子路由。必须是在父路由基础上加。export enum WorkLoad { |
上面评论里的图片没有上传成功, 可以重新上传一下吗 |
如果在父级路由配置了components,就会出现子级路由不渲染的问题,因为umi默认采用的是严格路由模式, 但是只要父级配置了routes,在预构建的.umi/core/routes.ts 中可以发现 exact属性是没有的,所以相当于exact:false。如果父级配置了component属性,子级组件就会默认渲染到父级组件的props. children,然而父级组件没有对props. children进行处理,这个时候你就会发现无论访问哪个子级路由显示的都是父级。如果手动设置父级的exact:true,得到的就是404。
1、父级路由不设置componet属性,在routes配置中增加一项和父级path一样的配置 也就是
2、使用redirect属性跳转,这种方式的弊端是点击父级路由时跳转会闪屏
|
microApp 的情况下,第二种方法 redirect 没作用了,没有执行跳转。 |
之前用的是 umi 脚手架跑的 |
@chenshuai2144 帅哥,能不能解决下这个问题。太常见了问题了 |
设置了选项 layout: 'mix', splitMenus: true, 需求是 动态加载子应用 和 子应用路由 的情况: routes 配置如下:
在 app.tsx 添加
我试着可以跳转过去了。 |
What happens?
ant-design-pro v5.0.0版本,开启layout,配置路由,在pages下面建3层目录结构,配置路由,无法跳转到最底层路由
最小可复现仓库(REQUIRED)
https://codesandbox.io/s/stoic-merkle-6jjfk?file=/config/config.ts
How To Reproduce
点击access,点击role,进入role页面 , 点击click。
Steps to reproduce the behavior: 1. 2.
Expected behavior 1. 2.
Context
The text was updated successfully, but these errors were encountered: