加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactjs – 使用react-router和webpack dev服务器的嵌套url路由

发布时间:2020-12-15 20:53:16 所属栏目:百科 来源:网络整理
导读:我在使用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
我在使用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件事.

webpack.config.js

devServer: {
    historyApiFallback: true <-- this needs to be set to true
}

routes.js

const routes = {
    childRoutes: [
        { path: '/',component: Register,childRoutes: [
            { path: 'step2',] },]
};

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读