反应路由,路径不工作,找不到包

React routing, path not working, bundle not found

以下路由效果很好并显示 AdminstratePage 组件:

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

但是这条路线:

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

...导致以下错误:

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

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

我正在使用 react-router-dom 4.1.2.

我的webpack.config.js:

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

我的index.html:

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

谢谢。

React-router v4 现在允许您使用正则表达式来匹配参数

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

它使用正则表达式路径

path-to-regexp

斜杠在这里看起来没用

filename: '/bundle.js'

也尝试定义 publicPath

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

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

解决此问题的另一种方法是将以下标记添加到您的 index.html 页面:

<base href="/">