簡體   English   中英

React Router更改路由/組件而不更改瀏覽器URL

[英]React Router to change route/component without changing browser URL

是否可以使用內部路由系統來渲染組件,但主瀏覽器路由不會改變?

因此,如果從mysite.com開始,它將呈現一個列表頁面,您可以進入實例頁面,但URL仍位於mysite.com ,依此類推。 如果刷新頁面,它將返回列表頁面。

您可以MemoryRouter使用MemoryRouter而不是Router 有關示例和文檔,請參見https://reacttraining.com/react-router/web/api/MemoryRouter

對於react-router版本3,您可以從history導入createMemoryHistory

const memoryHistory = createMemoryHistory(location);
<Router history={memoryHistory} routes={routes} />

版本3文檔: https//github.com/ReactTraining/react-router/blob/v3/docs/guides/Histories.md#creatememoryhistory

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM