React routing, path not working, bundle not found

一个人想着一个人 提交于 2019-12-20 05:34:07

问题


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.


回答1:


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/




回答2:


React-router v4 now allows you to use regexes to match params

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

It uses path-to-regexp

path-to-regexp




回答3:


Another way of solving this problem is to add the following tag to your index.html page:

<base href="/">


来源:https://stackoverflow.com/questions/50275901/react-routing-path-not-working-bundle-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!