简体   繁体   English

html-webpack-plugin上的动态React路由

[英]dynamic react routes at html-webpack-plugin

I am using react dynamic routes: 我正在使用反应动态路线:

<Route
      path="/"
      getComponent={(location, cb) => {
        System.import('./App')
              .then(loadRoute(cb))
              .catch(errorLoading);
      }}
 />

I have only one entry point at webpack: 我在webpack上只有一个入口点:

context: path.resolve(__dirname),
  entry: {
    app: './assets/js/components/index',
  },

and webpack is generating each app.js and one file for each route. webpack为每个路由生成每个app.js和一个文件。

在此处输入图片说明

But my generated html file does not have the import for these js files. 但是我生成的html文件没有这些js文件的导入。

Is there some setup for this? 有为此设置吗?

The point of doing code splitting this way is to avoid loading all the necessary code at the beginning, so it's normal that your html file doesn't load these scripts, as that would defeat the whole point! 以这种方式进行代码拆分的目的是避免在开始时加载所有必需的代码,因此,您的html文件不加载这些脚本是正常的,因为那样会破坏整个观点! :) :)

If everything works as it should, if you open the network inspector in your browser, you should see the async requests to fetch the route bundles as you navigate around your app. 如果一切正常,如果在浏览器中打开网络检查器,则在应用程序中浏览时,应该会看到异步请求以获取路由束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:找不到模块 &#39;html-webpack-plugin&#39; - Webpack (React) - Error: Cannot find module 'html-webpack-plugin' - Webpack (React) 构建 REACT 项目错误消息(“index.html”= index.html 的入口点 html-webpack-plugin) - Building REACT Project Error Message (Entrypoint html-webpack-plugin for "index.html" = index.html) 用于 webpack 插件 &#39;html-webpack-plugin&#39; 的 EJS 模板 - EJS Template for webpack plugin 'html-webpack-plugin' 带有 html-webpack-plugin 的 Webpack,全局安装时出错 - Webpack with html-webpack-plugin, error when installed globally html-webpack-plugin 入口点 undefined = index.html - html-webpack-plugin Entrypoint undefined = index.html html-webpack-plugin仅在根路由中注入js? - html-webpack-plugin is only injecting js in root route? 错误:html-webpack-plugin 无法缩小生成的输出 - Error: html-webpack-plugin could not minify the generated output Webpack&#39;html-webpack-plugin&#39;在每次构建后添加其他脚本 - Webpack 'html-webpack-plugin' adding additional script after each build html-webpack-plugin表示“文件名中的哈希”是什么意思? - What does the html-webpack-plugin mean when it says “hash in the filename”? 找不到模块:错误:无法解析“/node_modules/html-webpack-plugin/lib/loader.js” - Module not found: Error: Can't resolve '/node_modules/html-webpack-plugin/lib/loader.js'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM