![](/img/trans.png)
[英]How to change component with react-router without changing URL in address bar?
[英]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.