Answer the question
In order to leave comments, you need to log in
React Router v4 & Redux?
Good afternoon! Cannot sync React-router-dom with redux in any way.
app.js
import React from 'react';
import { render } from 'react-dom';
// Redux
import { createBrowserHistory } from 'history';
import { routerMiddleware, routerReducer as routing, syncHistoryWithStore } from 'react-router-redux';
import { applyMiddleware, createStore, combineReducers } from 'redux';
import { browserHistory } from 'react-router-dom';
import { Provider } from 'react-redux';
// App
import AppRouter from './routing/MainRouter';
import { loadState, saveState } from './utils/storage';
// Init Store
const reducers = {
routing
}
const middleware = routerMiddleware(browserHistory);
const store = createStore(combineReducers(reducers), loadState(), applyMiddleware(middleware))
const history = syncHistoryWithStore(createBrowserHistory() , store);
// Subscribe
store.subscribe(() => {
saveState(store.getState());
})
class App extends React.Component {
render() {
return (
<Provider store={store}>
<AppRouter history={history} />
</Provider>
)
}
}
render(<App/>, document.getElementById('app'))
const AppRouter = (props) => {
return (
<Router history={ props.history }>
<MainLayout>
<Switch>
<Route path='/' component={ MainBlogPageComponent } />
<Route exact path='/page/about' component={ AboutPageComponent } />
<Route exact path='/page/contact' component={ ContactPageComponent } />
</Switch>
</MainLayout>
</Router>
)
}
export default AppRouter;
const TopMenuComponent = (props) => {
return (
<div className='top-menu'>
<div className='container'>
<div className='row'>
<div className='col-md-3 col-sm-2'>
<div className='logo'>
<div className='logo__name'><a href='#'>Dikii Grigorii</a></div>
</div>
</div>
<div className='col-md-9 col-sm-10'>
<div className='text-right'>
<ul className='top-menu__list nav-list clear-list'>
<li><Link className='nav-list__link' to='/'>Главная</Link></li>
<li><Link className='nav-list__link' to='/'>Блог</Link></li>
<li><Link className='nav-list__link' to='/portfolio'>Портфолио</Link></li>
<li><Link className='nav-list__link' to='/page/about'>Обо мне</Link></li>
<li><Link className='nav-list__link' to='/page/contact'>Контакты</Link></li>
</ul>
</div>
</div>
</div>
</div>
</div>
)
}
export default TopMenuComponent;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question