React routing for sub-paths gives error in production mode

Viewed 42

So i'm building a react site using react-router-dom, in development mode while using the development server everything works fine, I can navigate to a sub-path i.e www.example.com/path/subpath but in production mode after deploying the react app and I navigate to a sub-path for example www.example.com/path/subpath I get this error printed to the console: Uncaught SyntaxError: Unexpected token '<' Uncaught ChunkLoadError: Loading chunk 5 failed. (missing: https://example.com/path/subpath/js/5.a6cbac98.chunk.js).

And this is a code snippet for my routing using react router dom:

 <>
      <Provider store={store}>
        <ThemeProvider theme={theme}>
          <MySnackBar />
          <Helmet>
            <meta
              name="description"
              content="Create an account or log into Emahd. Connect with friends, loved ones, and other people you know. Share photos, videos and screams, send messages and get updates."
            />
          </Helmet>
          <Router>
            <Suspense
              fallback={
                <Loading
                  styles={{
                    height: "100vh",
                  }}
                />
              }>
              <Switch>
                <Route path="/signup" component={SignUp} />
                <Route path="/forgot" component={ForgotPsw} />

                <Route
                  path="/user/:user"
                  render={() => (
                    <OtherUserAccount setSelectedTab={setSelectedTab} />
                  )}
                />
                <Route
                  path="/"
                  render={() => (
                    <AuthRender
                      selectedTab={selectedTab}
                      setSelectedTab={setSelectedTab}
                    />
                  )}
                />
              </Switch>
            </Suspense>
          </Router>
        </ThemeProvider>
      </Provider>
    </>

Please does anyone know the reason for this error, and how I can fix it? Thank you in advance.

0 Answers
Related