【发布时间】:2019-12-07 23:59:01
【问题描述】:
对于无效路由,我想显示NotFound 组件,但也不显示Navigation 组件:
const Layout: React.FunctionComponent = () => {
return (
<Router>
<Navigation />
<Switch>
<Route path="/explore" exact>
<ExploreIndex />
</Route>
<Route path="/explore/:id" exact>
<ExploreShow />
</Route>
<Route path="/" exact>
<Home />
</Route>
<Route component={NotFound} />
</Switch>
</Router>
);
};
如果我转到/aaaaaaa,我的NotFound 组件会加载,但我的Navigation 也会加载。我怎么能没有 Navigation 为这些路线渲染?
【问题讨论】:
标签: javascript reactjs react-router react-router-v4 react-router-dom