Answer the question
In order to leave comments, you need to log in
How to manage menu from different pages in ReactJS?
There are several pages that are placed in a certain layout. Layout is a header, content and navigation.
layout
class MainLayout extends React.Component {
render () {
return (
<div className="l-main">
<div className="l-main__header">
<Header/>
</div>
<div className="l-main__content">
{this.props.children}
</div>
<div className="l-footer">
<Navigation/>
</div>
</div>
);
}
}
class Routes extends Component {
render () {
return (
<Router history={history}>
<Route path='/' component={Application}>
<Route component={MainLayout}>
<Route path='index' component={IndexPage}/>
<Route path='main' component={MainPage}/>
<Route path='group' component={GroupPage}/>
</Route>
</Route>
</Router>
);
}
}
Answer the question
In order to leave comments, you need to log in
If you are making an application with arbitrary navigation, then usually you need to click "back" in the browser, for which a separate route is made to each page through the browser's address bar (history api).
If you are making a Wizard, then (in a simple case) you can do it as you described, hard-tie events to the UI. And in the general case, you need to implement your own routing inside the sorcerer. Your sorcerer must understand what page he is on and have a page switching map: {[page, event] => page}
As for the back button, make it a button, not a link, and use the history api :
// JavaScript module import
import { browserHistory } from 'react-router'
const goBack = () => browserHistory.previous()
<button type="button" onClick={goBack}>Назад</button>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question