【发布时间】:2019-12-23 16:33:51
【问题描述】:
当我为类别选择家具并为城市选择“San Jose, CA, USA”时,下面的推送会将 URL 重定向到 http://localhost:3000/search?category=furniture&city=San+Jose%2C+CA%2C+USA。
this.props.history.push({
pathname: '/search',
search: "?" + new URLSearchParams({category: this.category, city: this.userCity}).toString()
});
在 App.jsx 中,我定义了如下路由:
<Route path="/search/:category?/:city?" component={props => <EventSearchPage {...props} />}/>
在EventSearchPage 组件中,当我尝试访问this.props.match.params 时,我看到类别和城市都是undefined。
谁能告诉我哪里出错了?谢谢!
【问题讨论】:
标签: reactjs react-router