Ant-design-pro: 如何保存面包屑中父级路径的路由参数

Created on 10 May 2019  ·  11Comments  ·  Source: ant-design/ant-design-pro

面包屑中有些item是带参数的,怎么能将参数保留,方便进入子页面后直接通过点击面包屑进入父级页面?请教各路大神!

All 11 comments

直接固化到面包屑中就好了吧。上级目录 id 是唯一确定的。已经在 url 中了。

父级页面是通过location.query和location.state传参的,在面包屑组件里面只能获取当前路由的location内参数

我给你举个例子:

list/show/:id 在url中应该是 list/show/xxx ,你可以直接在 url 中 获取id的具体值

举个例子,我在A页面有两个传参id和name,从A页面进到它的子页面B传参是id和status,这个时候我从B通过面包屑返回A如何拿到A的两个参数呢?

面包屑中的路由应该有层级关系。
如果没有层级关系,最好的办法是 url 参数。 平级不应该通过面包屑进行导航的。尤其是代码参数的,会很困惑

这么说面包屑中只能获取list/show/:id这种形式路由的参数了,如果是通过代码传参进入页面就拿不到了,比如:router.push({
pathname: "/app/gift/add",
query: {
id: 111,
},
state: {
dataSource: {},
}
});

我这边需求大概是这种情况,
路由A:/customer/sever/rule?id=123&name=zwb,
路由B:/customer/sever/rule/edit?&type=CONFIG&ruleId=456,
A和B是父子级路由关系,我从B页面通过面包屑点击返回它的父级页面A,这个时候没有A的参数,类似这种情况如何处理比较好

找个中间商存一下,总要有个地方持久化的
建议你不要这样搞, rest 的方式推荐将关键参数放到 url中,不然用户刷新就会丢失掉状态

好的,现在用query方式传参还是能避免刷新的问题的,就是面包屑里面不好取。目前做法是放在缓存里临时存一下...

back 不行么,返回层级决定back调用次数

父级页面是通过location.query和location.state传参的,在面包屑组件里面只能获取当前路由的location内参数

配置的菜单组件,如何给location设置state内容呢?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cheung1111 picture cheung1111  ·  3Comments

suifan picture suifan  ·  3Comments

renyi818 picture renyi818  ·  3Comments

RichardStark picture RichardStark  ·  3Comments

kaoding picture kaoding  ·  3Comments