根目录下的 React-router 可选路径参数
React-router optional path parameters at root
我对如何从根目录执行(多个)可选路径参数有点困惑。我正在使用 react-router 3 和 redux 4.3。
据我了解,(/:param1)(/:param2)
应该可以,但我在加载应用程序时遇到以下错误:
[react-router] Location "/property/3633" did not match any routes.
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}/>
你需要添加一些相对路径,而不是直接给参数。 <Route path="/get/(:Type)/(:Id)" component={MyContainer}/>
今天遇到了同样的问题。我设法像这样解决它:
<Route path="/(:param1)(:/param2) component={SomeComponent}"
我对如何从根目录执行(多个)可选路径参数有点困惑。我正在使用 react-router 3 和 redux 4.3。
据我了解,(/:param1)(/:param2)
应该可以,但我在加载应用程序时遇到以下错误:
[react-router] Location "/property/3633" did not match any routes.
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}/>
你需要添加一些相对路径,而不是直接给参数。 <Route path="/get/(:Type)/(:Id)" component={MyContainer}/>
今天遇到了同样的问题。我设法像这样解决它:
<Route path="/(:param1)(:/param2) component={SomeComponent}"