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

Javascript CEP扩展中的react路由器(例如Premiere Pro),javascript,reactjs,react-router,adobe,complex-event-processing,Javascript,Reactjs,React Router,Adobe,Complex Event Processing,我正在尝试在CEP扩展中使用react路由器。我的路由如下所示: let prefix = decodeURIComponent(window.location.pathname).replace("index.html", "") <Router> <Switch> <Route exact path={prefix + "index.html"} component={MainComponent} /> &

我正在尝试在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>
let prefix=decodeURIComponent(window.location.pathname).replace(“index.html”,”)
这似乎是欺骗路由器接受扩展位置的唯一方法,因为它有一个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>
从'react Router dom'导入{Route,HashRouter作为路由器,Switch}

如果您使用的是Redux,则可以使用“createHashHistory”解决此问题。与接受的答案相同,这允许您使用正常路径。 下面是配置redux应用商店的情况

import { createStore, applyMiddleware } from 'redux';
import rootReducer from '../reducers/index';
import { createHashHistory } from 'history';
import { routerMiddleware } from 'connected-react-router';

const history = createHashHistory();
const routeMiddleware = routerMiddleware(history);
const middlewares = [routeMiddleware];

const configureStore = (initialState) => {
    return createStore(
        rootReducer(history),
        initialState,
        applyMiddleware(...middlewares)
    );
}

const store = configureStore({});

export default store;

因此,我可以通过完全删除“path”元素来解决与主组件路径不匹配的路由问题。剩下的问题是-如何获得相对路径“otherComponent”来匹配?