我试图使用一个反应路由器在一个CEP扩展。我的路线是这样的:
let prefix = decodeURIComponent(window.location.pathname).replace("index.html", "")
<Router>
<Switch>
<Route exact path={prefix + "index.html"} component={MainComponent} />
<Route path={prefix + "other/:otherId"} component={OtherComponent} />
</Switch>
</Router>这似乎是欺骗路由器接受扩展位置的唯一方法--因为它有一个file://path/to/cep/extention/index.html‘.的document.location我现在面临的问题是,这只适用于Mac,但始终无法与windows上的任何路径匹配。我怀疑这是因为windows上的位置看起来像是:'file:///C:/Program%20Files%20(x86)/Common%20Files/…be/CEP/extensions/index.html,而'C:‘混淆了路由器?
有没有办法欺骗路由器接受这种位置URI?
发布于 2019-04-17 11:41:07
简单的解决方案--使用HashRouter而不是BrowserRouter。这还允许使用正常路径:
import { Route, HashRouter as Router, Switch } from 'react-router-dom'
<Router >
<Switch>
<Route exact path="/" component={MainComponent} />
<Route path="/other/:otherId" component={OtherComponent} />
</Switch>
</Router>https://stackoverflow.com/questions/55725900
复制相似问题