question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Routes not displaying on refresh

See original GitHub issue

This might be completely obvious, but it’s not clear from the readme as far as I can tell. I have created some links and routes, and everything is working fine, as long as I start the app at the root /. If I navigate to a link, and then refresh the page, I get a Page Not Found error.

While I have been referencing the example, I’m still not sure why this is happening, except that I have a sneaky suspicion that it has something to do with the server.js file mentioned in the readme. In the example it states that you should run npm start. When checking the package.json I noticed, that this runs a series of commands which will in essence be your server. The readme doesn’t mention having to do any of this.

I feel like I am missing something completely obvious here? And if I am not, how would this work in production? Thanks for your help.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

89reactions
jacobgoh101commented, May 25, 2019

For a Rollup based dev environment generated from npx degit sveltejs/template my-svelte-project, you can fix it by adding -s to these 2 lines in package.json

  "scripts": {
     .....
    "start": "sirv public -s",
    "start:dev": "sirv public --dev -s"
  },

from https://www.npmjs.com/package/sirv-cli

-s, --single       Serve single-page applications
12reactions
colantuomocommented, Jul 17, 2021

Hi guys! The only thing that worked for was put "--single" inside writeBundle method in rollup.config.js

Like this:

    writeBundle() {
      if (server) return;
      server = require("child_process").spawn(
        "npm",
        ["run", "start", "--", "--dev", "--single"],
        {
          stdio: ["ignore", "inherit", "inherit"],
          shell: true,
        }
      );

      process.on("SIGTERM", toExit);
      process.on("exit", toExit);
    },
  };

Here is where I see that answer

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-router URLs don't work when refreshing or writing ...
The historyApiFallback is what fixed this issue for me. Now routing works correctly and I can refresh the page or type in the...
Read more >
Fixing the 'cannot GET /URL' error on refresh with React ...
The first, set up both client and server side routing. The second, redirect all server requests to /index.html which will download all the...
Read more >
Fixing React Router URL Doesn't Work When Refreshing or ...
In this article, you will learn how to fix the react-router URL that doesn't work when refreshing or writing. You will learn six...
Read more >
React Refresh Page Not Found : Fix in 2 Minutes ... - YouTube
In this video, we look at how to fix react refresh page not found under 3 minutes.NOTES If you found this...
Read more >
7.1 Fix Cannot Get/URL on Refresh | React Reach Router
Handing 404 Pages | Fix Cannot Get/URL on Page Refresh | Error | React Router | Reach Router | Handing 404 Pages |...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found