问题是,我需要在不更改URL的情况下通过3个组件进行路由,但也有更改路由的组件。
所以我将MemoryRouter嵌套在BrowserRouter中,但是当我进入MemoryRouter中时,就不会出来了。
我已经试过了:
const history=createBrowserHistory();
window.browserHistory=history;
<BrowserRouter history={history}>
<Switch>
<Route path="/quotes" component={QuotePage} />
<Route exact path="/" component={GreetingPage} />
</Switch>
</BrowserRouter>在MemoryRouter中,我有类似这样的东西。
<MemoryRouter>
<Switch>
<Route exact path="/" component={Form1} />
<Route path="/form2" component={Form2} />
</Switch>
<MemoryRouter>在Form 2中,我有一个函数调用
window.browserHistory.push("/quotes");现在"/quotes“在链接中可见,但是组件没有加载。
发布于 2020-11-06 19:47:59
使用html a标签而不是react-router Link组件来退出MemoryRouter。
https://stackoverflow.com/questions/63774473
复制相似问题