简体   繁体   English

为什么在未打开“精确”时,反应路由器无法选择不完全匹配的路由?

[英]Why is react-router not picking up a route that is not matched exactly when “exact” is not turned on?

I have the following situation: 我有以下情况:

render() {
    let redirectRoute = window["reactRoute"];

    if (redirectRoute !== undefined) {
        window["reactRoute"] = undefined;
        return <Redirect to={redirectRoute} push={true} />;
    }

    return (
        <div className="otherContentContainer">
            <Route path="/validation" render={() => <p>TestRender</p>} />
        </div>
    );
}

The listed snippet above is a boiled down and simplified version of the affected render() in my case. 上面列出的代码段是我所用的render()简化版本。

What's going on here is the following: My ASP.NET backend server returns a view which contains a subroute in window["reactRoute"] (This is something I came up with to get around the client-server routing problem with ASP.NET & React routing). 这是怎么回事:我的ASP.NET后端服务器返回一个视图,该视图在window["reactRoute"]包含一个子路由(这是我想出的解决ASP.NET和客户端-服务器路由问题的方法。反应路由)。

It then properly redirects to the following URL: 然后,它将正确重定向到以下URL:

/Logon/validation/success

After the redirect is successful, the redirect part is not relevant anymore and I try to render certain components, in this case a simple <p> for testing purposes based on that route. 重定向成功后,重定向部分不再重要,我尝试渲染某些组件,在这种情况下,将基于该路由使用简单的<p>进行测试。

However, <Route path="/validation" render={() => <p>TestRender</p>} /> does not trigger at all, and I don't understand why. 但是, <Route path="/validation" render={() => <p>TestRender</p>} />根本不会触发,我也不知道为什么。

Here is what I picked up from the React router docs: 这是我从React路由器文档中挑选的:

在此处输入图片说明

Given that I didn't configure my <Route> to be exact , I don't quite see how I am different to the example. 鉴于我没有exact配置<Route> ,所以我不太明白与示例有何不同。

Can you point me to where I'm going wrong? 您能指出我要去哪里了吗?

Seems like a problem with /Logon/ . 似乎是/Logon/的问题。 Try the following instead: 请尝试以下操作:

<Route path="/Logon/validation" render={() => <p>TestRender</p>} />

Alternatively, you can set the basename property in the *Router component call (as mentioned here ). 另外,您也可以设置basename在属性*Router组件调用(如提到这里 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM