我正在尝试在 CEP 扩展中使用 react 路由器。我的路由如下所示:
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>
这似乎是欺骗路由器接受扩展位置的唯一方法 - 因为它的 document.location 为“file://path/to/cep/extention/index.html”。 我现在面临的问题是,这仅适用于 Mac - 但始终无法匹配 Windows 上的任何路径。我怀疑这是因为 Windows 上的位置如下所示: 'file:///C:/Program%20Files%20(x86)/Common%20Files/...be/CEP/extensions/extension-name/index.html' 和“C:”混淆了路由器?
有什么办法可以欺骗路由器接受这种位置URI吗?
最佳答案
简单的解决方案 - 使用 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>
关于javascript - CEP 扩展中的 React-router(例如 Premiere Pro),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55725900/