0
我正在创建一个应用程序,其中显示基于路由器位置的数据 例如 localhost:8080/us应该显示“USA flag and some text to United States” 本地主机:8080 /在应该显示“印度国旗和与印度的一些文本”更改基于路由器的应用程序状态
我有两个减速器一个印度等对美国和我有一个根减速机为以下所示的
import {combineReducers} from 'redux';
import IndiaData from './IndiaData';
import USData from './UsData';
const rootReducer = combineReducers({
IndiaData,
USData,
ActiveData
});
export default rootReducer;
我的样本减速IndiaData是波纹管
export default function() {
return [
{
"StateName": "AP",
"StateImg": "../static/image1.jpg",
},
{
"StateName": "TS",
"StateImg": "../static/image2.jpg",
},
{
"StateName": "TN",
"StateImg": "../static/image3.jpg",
}
]
}
我使用mapStateToProps在我的反应组件,请在下面找到
import React, {Component} from 'react';
import {connect} from 'react-redux';
import styles from '../styles/custom.css'
class CountryData extends React.Component {
Country(){
return this.props.usdata.map((Data)=>{
return(
<div className="col-md-4">
<img className="panel" src={Data.StateImg}/>
<p>{Data.StateName}</p>
</div>
);
})
}
render(){
return(
<div>
<div className="container margin-top jumbotron">
{this.Country()}
</div>
</div>
);
}
}
function mapStateToProps (state){
return {
indiadata: state.IndiaData,
usdata: state.USData,
};
}
export default connect(mapStateToProps)(CountryData);
和我的路由器配置如下图
import React from 'react';
import {Route, IndexRoute} from 'react-router';
import App from './components/app';
import CountryData from './components/CountryData';
export default (
\t <Route path ="/" component={App}>
\t \t <Route path="in" component={CountryData} />
\t \t <Route path="us" component={CountryData} />
\t </Route>
);
所以最后,我应该能读什么是出现在URL路径,然后显示,美国数据或印度的数据动态,能对某些一个人请帮我一下吗?
非常感谢您的支持!
感谢您的快速帮助和道歉迟到的答复 我用第二种方法,它是对我工作的罚款唯一担心的是如果我有21个国家的我需要编写21个不同的连接组件。 – Ravi