Something I stumble upon is understanding how to use Material-UI tabs. I found many posts but each target a different version of material-UI and each give a completely different way of implementation.
The web application I an creating is an analytical dashboard. I have 3 parts on the page.
In the main body part I want to have a tabs component and dashboard component. Selecting different tab will display different dashboard component.
I started with the default Tabs component which didn’t display it right, and then I read that I need to do it using React Router, but then it depends on which router version I use.
It might be that my SPA understanding is also lacking as to why I should involve router when using Tabs.
My setup: Latest React 16.x Latest React -router 4.x Latest Material-UI 1.0.3 Using Redux as well
here is small example I created using App bar and tabs from Material-ui with react-router
<BrowserRouter>
<div className={classes.root}>
<AppBar position="static" color="default">
<Tabs
value={this.state.value}
onChange={this.handleChange}
>
<Tab label="Item One" component={Link} to="/one" />
<Tab label="Item Two" component={Link} to="/two" />
</Tabs>
</AppBar>
<Switch>
<Route path="/one" component={PageShell(ItemOne)} />
<Route path="/two" component={PageShell(ItemTwo)} />
</Switch>
</div>
here I have used Switch to introduce routes for the application and Link component to trigger route changes
working example: https://codesandbox.io/s/04p1v46qww
I have added transition animation for the example feel free to remove the animation if you wish.
That's when we want add users to go through routes urls and find the relevant pages ex: /home will render home page and /profile for profile page.
with react-router you can use many functionalities like go through history that means you can view previous pages you went with going back.
pass url params so we can render components as params changes
however If a developer wish he can design and finish an app without using routes. It will be a mess with conditional rendering but still.
from the user's view, it is a regular web app (he doesn't need to know how it is designed: SPA or otherwise) and it should work as any web app/website should work. That's what routing does same time help us to do more efficient development.
use this for tabs without using routes: https://codesandbox.io/s/qlq1j47l2w
Hope this will help you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With