【问题标题】:ReactJS routing onEnter replace issueReactJS 路由 onEnter 替换问题
【发布时间】:2021-02-16 09:25:05
【问题描述】:

我有 2 条路线

{
    path: '/a/:aP1/:aP2/',
    component: APage,
    onEnter: (nextState, replace) => {
            replace({
                state: {
                    status: 301
                },
                pathname: `/b/${nextState.params.aP1}/${nextState.params.aP2}/`
            });
            
    }
},
{
    path: '/b/:bP1/:bP2/',
    component: BPage,
    onEnter: (nextState, replace) => {
            replace({
                state: {
                    status: 301
                },
                pathname: `/a/${nextState.params.bP1}/${nextState.params.bP2}/`
            });
            
    }
}

问题是当我进行重定向时,它会将路径名附加到路由路径。所以不是这个重定向/a/p1/p2 我得到这个 - /b/a/p1/p2。如何解决这个问题?

【问题讨论】:

    标签: reactjs redirect react-router


    【解决方案1】:

    在重定向路径名中添加前导点: '../a/blah-blah'

    【讨论】:

      猜你喜欢
      • 2017-08-21
      • 1970-01-01
      • 2020-10-18
      • 2018-01-27
      • 2018-04-30
      • 1970-01-01
      • 2018-10-16
      • 2021-04-09
      相关资源
      最近更新 更多