我正在使用Office UI Fabric创建具有不同视图的应用程序。
导航栏.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' }
]
}
]}
/>
);
}
}
在 App.js 中,我只返回和 . 问题是,当我单击 NavBar 的项目时,页面将刷新并在该路由中加载整个视图。我如何只重新加载组件,而不是整个页面?
这是 App.js 渲染返回中的路由部分:
<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>
我有这样的路线:
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 />
}
];
该页面正在运行,但是如果我单击一个,我如何使用它来指定导航栏项目,然后只渲染目标组件?