【发布时间】:2018-09-29 04:16:15
【问题描述】:
我对如何从根目录执行(多个)可选路径参数感到有些困惑。我正在使用 react-router 3 和 redux 4.3。
据我了解,(/:param1)(/:param2) 应该可以工作,但在加载应用程序时出现以下错误:
[react-router] 位置“/property/3633”不匹配任何路由。
index.js:
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { Router, browserHistory, Route } from 'react-router';
import { syncHistoryWithStore } from 'react-router-redux';
import configureStore from './store/configureStore';
import {MyContainer} from "./containers/MyContainer";
const store = configureStore();
const history = syncHistoryWithStore(browserHistory, store);
ReactDOM.render(
<Provider store={store}>
<Router history={history}>
<Route path="/(/:Type)(/:Id)" component={MyContainer}/>
</Router>
</Provider>,
document.getElementById('root'),
);
仅供参考,我试过了:
path="(/:Type)(/:Id)"
path="(/:Type)/(/:Id)"
path="/(/:Type)/(/:Id)"
path="/(/:Type)(/:Id)"
path="/:Type/:Id" // Only works when params are supplied
这很有效:
<Route path="/test(/:Type)(/:Id)" component={MyContainer}/>
但同样,这不是:
<Route path="/(/:Type)(/:Id)" component={MyContainer}/>
【问题讨论】:
-
path="(/:Type)(/:Id)"怎么样?
标签: reactjs react-router react-router-redux