nested url routing using react-router and webpack dev server

前端 未结 2 738
被撕碎了的回忆
被撕碎了的回忆 2020-12-20 17:05

I\'m having some issues working with react-router and webpack-dev-server to achieve nested url routing.

webpack.config.js

output: {
         


        
2条回答
  •  离开以前
    2020-12-20 17:35

    I figured it out. 2 things that is needed to enable this.

    webpack.config.js

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


    routes.js

    const routes = {
        childRoutes: [
            { path: '/', component: Home },
            { path: '/login', component: Login },
            { path: '/register', component: Register, childRoutes: [
                { path: 'step2', component: SecondStep },
            ] },
        ]
    };
    

提交回复
热议问题