首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react CEP扩展中的路由器(例如Premiere Pro)

react CEP扩展中的路由器(例如Premiere Pro)
EN

Stack Overflow用户
提问于 2019-04-17 10:54:22
回答 1查看 212关注 0票数 0

我试图使用一个反应路由器在一个CEP扩展。我的路线是这样的:

代码语言:javascript
复制
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?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-17 11:41:07

简单的解决方案--使用HashRouter而不是BrowserRouter。这还允许使用正常路径:

代码语言:javascript
复制
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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55725900

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档