![](/img/trans.png)
[英]How to detect matched route from a component outside of the <Route/> component that was matched using react-router?
[英]Why is react-router not picking up a route that is not matched exactly when “exact” is not turned on?
我有以下情況:
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>
);
}
上面列出的代碼段是我所用的render()
簡化版本。
這是怎么回事:我的ASP.NET后端服務器返回一個視圖,該視圖在window["reactRoute"]
包含一個子路由(這是我想出的解決ASP.NET和客戶端-服務器路由問題的方法。反應路由)。
然后,它將正確重定向到以下URL:
/Logon/validation/success
重定向成功后,重定向部分不再重要,我嘗試渲染某些組件,在這種情況下,將基於該路由使用簡單的<p>
進行測試。
但是, <Route path="/validation" render={() => <p>TestRender</p>} />
根本不會觸發,我也不知道為什么。
這是我從React路由器文檔中挑選的:
鑒於我沒有exact
配置<Route>
,所以我不太明白與示例有何不同。
您能指出我要去哪里了嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.