nested url routing using react-router and webpack dev server

前端 未结 2 737
被撕碎了的回忆
被撕碎了的回忆 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 },
            ] },
        ]
    };
    
    0 讨论(0)
  • 2020-12-20 17:57

    If you use hashHistory instead of createBrowserHistory() it will keep the server from requesting to your current url on your server.

    export default (<Router routes={routes} history={hashHistory} />);
    
    0 讨论(0)
提交回复
热议问题