【发布时间】:2020-04-06 08:08:29
【问题描述】:
我有两条路线,一条基本路线和一条客户路线。客户路线采用 customerId 参数。
<HashRouter>
<Switch>
<Route path="/mapper/:mappingId/" exact component={Mapper}/>
<Route path="/" exact component={App} />
</Switch>
</HashRouter>
然后在 react 组件中我这样称呼它来导航
window.open(`/customer/${customerId}`)
但是当我导航时它只是转到 App 组件。我必须使用 HashRouter,因为 react 应用程序包含在 Electron 中。 BrowserRouter 在网络上工作
我导航时得到的网址是这样的: http://localhost:3000/customer/ca023754-bb75-4f64-a19c-958525b53e12#/ 我还尝试在 Route 中添加反斜杠 /customer/:customerId/,但效果不佳
我已经阅读了How to use React Router with Electron?,但它并没有真正起作用
【问题讨论】:
-
最好将“/”放在最前面,并带有确切的路径,并将您的路线放在开关内。
-
我更新了代码 sn-p 并尝试在路径变量之前和之后放置“精确”。还是不行
-
把默认路由'/'放在第一位。
标签: reactjs react-router