反应路由,路径不起作用,找不到包 [英] React routing, path not working, bundle not found

查看:44
本文介绍了反应路由,路径不起作用,找不到包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下路线效果很好并显示了 AdministratePage 组件:

 

但是这条路线:

 

...导致以下错误:

<块引用>

http://localhost:8080/admin/bundle.js 404(未找到))

我哪里出错了?我不能使用任何路径吗?

我使用的是 react-router-dom 4.1.2.

我的 webpack.config.js :

 输出:{路径:path.resolve('dist'),文件名:'/bundle.js'},

我的 index.html:

 

谢谢.

解决方案

Slash 在这里看起来没用

文件名:'/bundle.js'

也尝试定义publicPath

输出:{文件名:'bundle.js',路径:path.resolve('dist'),公共路径:'/',},

https://webpack.js.org/guides/public-path/

The following route works great and displays the AdministratePage component:

 <Route path="/admin" component={AdministratePage} />

However this route:

 <Route path="/admin/all" component={AdministratePage} />

...results in the following error:

http://localhost:8080/admin/bundle.js 404 (Not Found)

Where do I go wrong? Am I not allowed to use any path?

I'm using react-router-dom 4.1.2.

My webpack.config.js :

  output: {
        path: path.resolve('dist'),
        filename: '/bundle.js'
    },

My index.html:

   <div id="app"></div>

Thank you.

解决方案

Slash looks useless here

filename: '/bundle.js'

Also try to define publicPath

output: {
  filename: 'bundle.js',
  path: path.resolve('dist'),
  publicPath: '/',
},

https://webpack.js.org/guides/public-path/

这篇关于反应路由,路径不起作用,找不到包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆