admin管理员组文章数量:1430995
I am having one use case.
My main react application (container) is loading (mounting) another react child application (module), which is implemented using react-router
.
When the route changes in the child application, it is also changing the main application URL.
Is there any way to change the route without changing URL?
I know this is possible without react-router
in the child application, by just changing ponent based on state.
But how can we achieve the same with react-router
?
It should be kind of head less application, please help your thoughts.
I am having one use case.
My main react application (container) is loading (mounting) another react child application (module), which is implemented using react-router
.
When the route changes in the child application, it is also changing the main application URL.
Is there any way to change the route without changing URL?
I know this is possible without react-router
in the child application, by just changing ponent based on state.
But how can we achieve the same with react-router
?
It should be kind of head less application, please help your thoughts.
Share Improve this question edited Oct 4, 2018 at 9:05 R.Duteil 1,2371 gold badge14 silver badges28 bronze badges asked Oct 4, 2018 at 6:08 user7175350user7175350 1012 silver badges9 bronze badges 1- Please, explain your case further. stackoverflow./help/mcve would help to understand your case better. You likely need memory router or custom router, depending on your case – Estus Flask Commented Oct 4, 2018 at 6:40
1 Answer
Reset to default 4If you want to use react-router
without changing the URL you may consider using a MemoryRouter
import { MemoryRouter } from 'react-router';
<MemoryRouter>
<div>
<Route path="/first" ponent={FirstComponent} />
<Route path="/second" ponent={SecondComponent} />
</div>
</MemoryRouter>
And use it like usual:
this.props.history.push('/second')}
A router that keeps the history of your "URL" in memory (does not read or write to the address bar). Useful in tests and non-browser environments like React Native.
https://github./ReactTraining/react-router/blob/master/packages/react-router/docs/api/MemoryRouter.md
You just need to be aware that MemoryRouter
does not change the browser history, thus you won't be able to press the back button. If you want to keep a back button, you will need to handle it manually.
this.props.history.goBack() // when a user click on the back button
this.props.history.goForward() // when a user click the forward button
本文标签: javascriptHow to change component with reactrouter without changing URL in address barStack Overflow
版权声明:本文标题:javascript - How to change component with react-router without changing URL in address bar? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745576675a2664372.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论