React nested route fails to load on refresh

后端 未结 3 1010
清酒与你
清酒与你 2021-02-03 10:44

I have a React app with navigation powered by react-router that I run in development with webpack-dev-server and the history fallback option enabled. H

3条回答
  •  猫巷女王i
    2021-02-03 11:11

    It doesn't work because it can't load your javascript bundle. I'm guessing that the problem is with your path in script tag in HTML. Probably you have specified the path to app.js with dot at the beginning like this one , if this is true please remove dot and check if the problem still exists

    Let's illustrate what is the difference between ./app.js and /app.js

    Case 1. You are loading page using first level of routes like / or /intro

    • ./app.js: HTML tries to load script from http://address/app.js
    • /app.js: HTML tries to load script from http://address/app.js

    No difference

    Case 2. You are loading page using second level of routes /build/pattern

    • ./app.js: HTML tries to load script from http://address/build/app.js - doesn't exist
    • /app.js: HTML tries to load script from http://address/app.js - OK

提交回复
热议问题