I'm using Office UI Fabric to create app with different views.
navbar.js:
import React, { Component } from 'react';
import { Nav } from 'office-ui-fabric-react/lib/Nav';
export default class NavBar extends Component {
render() {
return (
<Nav
groups={[
{
links: [
{ name: 'Home', key: 'Home', url: '/' },
{ name: 'Activity', key: 'Activity', url: '/activity' },
{ name: 'News', key: 'News', url: '/news' },
{ name: 'Documents', key: 'Documents', url: '/documents' }
]
}
]}
/>
);
}
}
and in App.js, I just return and . The problem is, when I click on the item of NavBar, the page will refreshed and load the whole view in that route. How I can reload just the component, not the whole page?
Here's the routing part in the App.js render return:
<div className="body">
<NavBar />
<Router>
<div style={{ flex: 1}}>
{routes.map((route, index) => (
<Route
key={index}
path={route.path}
exact={route.exact}
component={route.main}
/>
))}
</div>
</Router>
</div>
and I have the routes like:
const routes = [
{
path: "/",
exact: true,
main: () => <Home />
},
{
path: "/activity",
exact: true,
main: () => <Activity />
},
{
path: "/news",
exact: true,
main: () => <News/>
},
{
path: "/documents",
exact: true,
main: () => <Documents />
}
];
And the page is working, but how I can use to specify the Nav bar items if I click on one, then just render the target component?