我对如何从根执行(多个)可选路径参数感到困惑。我使用 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}/>
答案 0 :(得分:1)
您需要添加一些实际路径,而不是直接给出参数。 <Route path="/get/(:Type)/(:Id)" component={MyContainer}/>
答案 1 :(得分:1)
今天有同样的问题。我设法这样解决:
<Route path="/(:param1)(:/param2) component={SomeComponent}"