【发布时间】:2017-07-11 23:31:02
【问题描述】:
任何人都可以告诉我当您在服务器端使用 react-router 更改路由的 URL 以进行路由时如何调用操作。
我正在使用 react-router 的 browserHistory 将我的输入推送到 url。
import React from 'react';
import { connect } from 'react-redux';
import { browserHistory } from 'react-router';
class findBirthdays extends Component {
constructor(props){
super(props);
}
openCalender(){
// here I open the date picker and let user select the date
// then I add that date in the URL as "localhost:3000/find/?date=22-02-2017"
// here I get confused as I do not know now how to dispatch the action or
// how to access url params in a specific actions after dispatching that action
}
render(){
return (
// repeating all the birthday that are available on selected date
)
}
}
const mapStateToProps = (state) => {
return {
birthdayList: state.birthdays,
};
};
export default connect(mapStateToProps)(findBirthdays);
我有很多输入,并且在每个输入更改事件中,都会附加 URL,这应该会导致调度操作并获得正确的结果。
我是 react 和 redux 的新手,所以如果有人可以建议是否可以这样做或如何解决这个问题,那将是有帮助的。 谢谢大家。
【问题讨论】:
-
所以你想
dispatch和action或者只是将route更改为date-query? -
@JyothiBabuAraja 如果我选择日期,它应该添加到 url 并且 url 更改应该调度将采取 url 参数进行进一步处理的操作。我已经完成了将它添加到 url 部分。我需要第二部分的帮助。
-
你可以阅读像
this.props.location.query.date这样的url查询参数 -
@JyothiBabuAraja 我想在一个不在反应组件中的动作中阅读它。
-
然后在调度您的操作时将其作为参数发送。
标签: reactjs redux react-router react-redux react-router-redux