gpt4 book ai didi

reactjs - 根目录下的 React-router 可选路径参数

转载 作者:行者123 更新时间:2023-12-03 13:47:31 28 4
gpt4 key购买 nike

我对如何从根执行(多个)可选路径参数有点困惑。我正在使用 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="/(:param1)(:/param2) component={SomeComponent}"

关于reactjs - 根目录下的 React-router 可选路径参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49907876/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com