【发布时间】:2020-06-21 21:08:14
【问题描述】:
我目前正在使用 React 路由器。与<Switch> 选项相反,我更喜欢路由配置文件的语法和映射路由数组以呈现路由。
{routes.map(route => {
return (
<PrivateRoute
key={route.path}
path={route.path}
exact
component={route.component}
/>
);
})}
上述用例有没有办法为所有非精确匹配的路由设置一个 404 组件。
我见过像这样的<Switch> 方法:https://reacttraining.com/react-router/web/example/no-match。如前所述,我更喜欢在路由配置文件中声明所有路由,包括路径、组件和面包屑名称。如果我沿着 Switch 路线走,那么路线配置仅用于面包屑并且变得不那么有用
【问题讨论】:
标签: reactjs react-router react-router-dom react-router-redux