作家
登录

【翻译】基于 Create React App路由4.0的异步组件加载(Code Splitting)

作者: 来源: 2017-07-07 12:05:26 阅读 我要评论

 ({ childProps }) => ( 
  •   <Switch> 
  •     <AppliedRoute path="/" exact component={AsyncHome} props={childProps} /> 
  •     <UnauthenticatedRoute path="/login" exact component={AsyncLogin} props={childProps} /> 
  •     <UnauthenticatedRoute path="/signup" exact component={AsyncSignup} props={childProps} /> 
  •     <AuthenticatedRoute path="/notes/new" exact component={AsyncNewNote} props={childProps} /> 
  •     <AuthenticatedRoute path="/notes/:id" exact component={AsyncNotes} props={childProps} /> 
  •     { /* Finally, catch all unmatched routes */ } 
  •     <Route component={AsyncNotFound} /> 
  •   </Switch> 
  • );  
  • 只需几回更改就相当酷了。我们的app都是设置了代码瓜分而的。也没有增长太多的复杂性。

    这里我们看看之前的┞封个src/Routes.js路由文件

    1. import React from 'react'
    2. import { Route, Switch } from 'react-router-dom'
    3. import AppliedRoute from './components/AppliedRoute'
    4. import AuthenticatedRoute from './components/AuthenticatedRoute'
    5. import UnauthenticatedRoute from './components/UnauthenticatedRoute'
    6.  
    7. import Home from './containers/Home'
    8. import Login from './containers/Login'
    9. import Notes from './containers/Notes'
    10. import Signup from './containers/Signup'
    11. import NewNote from './containers/NewNote'
    12. import NotFound from './containers/NotFound'
    13.  
    14. export default ({ childProps }) => ( 
    15.   <Switch> 
    16.     <AppliedRoute path="/" exact component={Home} props={childProps} /> 
    17.     <UnauthenticatedRoute path="/login" exact component={Login} props={childProps} /> 
    18.     <UnauthenticatedRoute path="/signup" exact component={Signup} props={childProps} /> 
    19.     <AuthenticatedRoute path="/notes/new" exact component={NewNote} props={childProps} /> 

        推荐阅读

        浪潮将发布服务器新品 聚焦智慧计算

      【51CTO.com原创稿件】 2017年7月6日,海潮经由过程其官方微信宣布了将于7月12日宣布其新一代办事器&mdash;&m>>>详细阅读


      本文标题:【翻译】基于 Create React App路由4.0的异步组件加载(Code Splitting)

      地址:http://www.17bianji.com/lsqh/36075.html

    关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)