我在使用react-router和webpack-dev-server时遇到了一些问题,无法实现嵌套的url路由.
webpack.config.js
output: { path: path.resolve(__dirname,'build'),publicPath: "/",<-- this enabled routing to /register/step2 filename: "js/bundle.js",},
routes.js
const routes = { childRoutes: [ { path: '/',component: Home },{ path: '/login',component: Login },{ path: '/register',component: Register },{ path: '/register/step2',component: SecondStep },] }; export default (<Router routes={routes} history={createBrowserHistory()} />);
当在appliation中点击时,我可以进入/ register / step2,但是一旦我在浏览器中点击刷新,我的common.js和bundle.js就丢失了:404,因为它试图从/ register /目录加载所有东西.
有人可以帮忙吗?谢谢.
我想到了.启用此功能所需的2件事.
原文链接:https://www.f2er.com/react/301236.htmlwebpack.config.js
devServer: { historyApiFallback: true <-- this needs to be set to true }
routes.js
const routes = { childRoutes: [ { path: '/',component: Register,childRoutes: [ { path: 'step2',] },] };