How to make react router work with static assets, html5 mode, history API and nested routes?

前端 未结 4 569
北荒
北荒 2020-12-28 14:44

I thought I was starting to understand React Router, but I hit a new wall when adding a library that loads css for its components. Everything works fine when a navigate from

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-28 15:44

    I solved this thanks to react-script:2+

    You just have to create a js file called setupProxy.js, it will be loaded by the developement server. Now you have complete control over your proxy:

    const proxy = require('http-proxy-middleware');
    
    module.exports = function(app) {
        console.log("configuring development proxies to point to localhost:4000")
        app.use(proxy('/api', { target: 'http://localhost:4000/' }));
        app.use(proxy('/graphql', { target: 'http://localhost:4000/' }));
    };
    

    https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#configuring-the-proxy-manually

提交回复
热议问题