我的 url 有问题,我需要不是从 localhost:8081 而是从 localhost:8081/admin 运行我的应用程序,所以所有页面都显示 404,其中有 /....,无论如何主页也不起作用很好,在 index.html 我也有标签,文件的例子。
<link href="../public/css_admin/fonts/fonts.css" rel="stylesheet"/>
Webpack 配置
var path = require('path');
module.exports = {
entry: './src/index.jsx',
output: {
path: path.resolve('dist'),
publicPath: '/admin/',
filename: 'bundle.js'
},
resolve: {
extensions: ['.js', '.json', '.jsx']
},
.....
devServer: {
contentBase: './',
historyApiFallback: true,
host: 'localhost',
port: 8081
},
externals: {
config: JSON.stringify({
apiUrl: '..../rest/v1'
})
}
}
应用路线
render() {
return (
<Router history={history} basename="admin">
<div>
<Switch>
<PrivateRoute exact path="/" component={MainIndexPage} refresh={false} />
<PrivateRoute exact path="/staff" component={StaffPage} refresh={false} />
<Route path="/register" component={RegisterPage} />
</Switch>
</div>
</Router>
);
}