Basename not working properly

后端 未结 3 1994
闹比i
闹比i 2021-02-20 03:20

I\'m attempting to use a basename with react-router as documented on the react-router docs. This is due to base href being deprecated.

Here is what I have now:

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-20 03:58

    Here is how I managed to get it to work

    Set Router basename to your subdirectory like this

    If you used create-react-app and are building using npm run build you need to set homepage in package.json for the paths to be correct in the production build

    homepage: "{http://www.the-url.com/subdirectory}"

    For the nginx config, let's assume your index.html is under /path/to/subdirectory/index.html. Then the following should work

    location /subdirectory {
        root /path/to;
        try_files $uri $uri/ /subdirectory/index.html;
    }
    

提交回复
热议问题