I have an following app:
index.js
const store = createStore(rootReducers, applyMiddleware(createLogger()));
store.dispatch(fetchArticles());
ReactDOM.render(
<Provider store={store}>
<Router>
<Switch>
<Route exact path='/' component={ArticlesPage}/>
<Route path='/search' component={SearchPage}/>
</Switch>
</Router>
</Provider>,
document.getElementById('root')
);
ArticlesPage.js
const ArticlesPage = ({groups, onSearch}) => (
<Grid>
<SearchBoxWithImages onSearch={onSearch}/>
<CategorySections groups={groups}/>
</Grid>
);
const mapStateToProps = state => ({
groups: state.articles.groups
});
const mapDispatchToProps = dispatch => ({
onSearch: (q) => dispatch(searchArticles(q))
});
export default withRouter(connect(
mapStateToProps,
mapDispatchToProps
)(ArticlesPage));
fetchArticles
and searchArticles
are an redux actions.
I wanna handle that case:
- enter site (url
/
) - after search, handled by a
SearchBoxWithImages
component, I wanna change an url into/search?q=term
(term is a callback from theonSearch
handler) - call action
searchArticles
to set redux state
Currently only state was changed (because of call the searchArticles
action). Url isn't change, therefore SearchPage
container wasn't call.