我一直在使用 CoreUI 来更深入地学习 React。在一个名为“containers”的文件夹中,有一段代码似乎在遍历包含所有路由的文件。
<main className="main">
<AppBreadcrumb appRoutes={routes}/>
<Container fluid>
<Switch>
{routes.map((route, idx) => {
return route.component ? (<Route key={idx} path={route.path} exact={route.exact} name={route.name} render={props => (
<route.component {...props} />
)} />)
: (null);
},
)}
<Redirect from="/" to="/dashboard" />
</Switch>
</Container>
</main>
下面是 routes.js 文件的一个简短示例:
const routes = [
{ path: '/', exact: true, name: 'Home', component: DefaultLayout },
{ path: '/dashboard', name: 'Dashboard', component: Dashboard },
{ path: '/theme', exact: true, name: 'Theme', component: Colors },
据我了解,代码正在尝试检查路径并仅根据浏览器的路径呈现组件,这是正确的吗?你能用普通的 IF-Else 范式解码上面的代码吗?