17.webpack解决当页面路由问题

2019-03-27  本文已影响0人  风雪之隅_b6f7

    <BrowserRouter>

                    <Route path="/"  exact component={Home}/>

                    <Route path="/list" component={List}/>

        </BrowserRouter>

localhost:8080/能正确找到

localhost:8080/list找不到

devServer: {

        // historyApiFallback: {

        //  rewrites: [

        //      { from: /\.*/, to: '/index.html' }

        //    ]

        // },

        historyApiFallback:true,//加这个可以解决找不到文件的问题

        contentBase: './dist',

        open: true,

        port: 8080,

        hot: true,

        hotOnly: true,

        proxy:{

            '/react/api':{

                target:'http://www.dell-lee.com',

                changeOrigin: true,//解决后台对跨域的限制

                secure: false,//https时需配置

                // pathRewrite:{'header.json':'demo.json'}//    将header.json接口未写好时暂时转发到写好demo.json上去测试,上线后则注销此转发

                headers:{

                  host:'www.dell-lee.com',

                  cookie:'sfsd'

              }

            }

        }

    },

上一篇 下一篇

猜你喜欢

热点阅读