【发布时间】:2019-12-15 23:23:45
【问题描述】:
我们正在使用带有 Razor 视图(纯后端堆栈)的 dotnet 编写的项目。我们计划使用react-router-dom 将每个视图移动到React,以处理客户端和服务器中的路由。
我们的想法是逐页移动,而不是大爆炸,因为该项目已经在生产中。
客户端路由器
import { Router } from 'react-router-dom'
import { createBrowserHistory, History } from 'history'
const history: History = createBrowserHistory({ basename: baseUrl })
<Router history={history}>
<Switch>
<Route path="/example" component={Example} />
...
</Switch>
</Router>
服务器路由器
import { StaticRouter } from 'react-router-dom'
<StaticRouter
basename={basename}
context={routerContext}
location={params.location.path}
>
<Switch>
<Route path="/example" component={Example} />
...
</Switch>
</StaticRouter>
问题
当我从 /example(在 react 路由器中)导航到 /(在 .net 路由器中)然后我尝试返回 /example 时,似乎没有过渡到 react 路由器并且浏览器历史记录保留在/。
【问题讨论】:
标签: javascript reactjs react-router react-router-dom