Join the conversation

Sign in to join this conversation, and others like it, in the communities you care about.

ZEIT

Our mission is to make cloud computing as easy and accessible as mobile computing. You can find our Next.js community here.

ZEIT / Now

Static Routing Configuration Issues

Static Routing Configuration Issues

ZEIT/Now · January 11, 2019 at 1:16pm

Static Routing Configuration Issues

ZEIT / Now · January 11, 2019 at 1:16pm
Hi All,
I'm trying to push a static site and having routing issues.
I normally use Surge for this which is really nicely configured (default is index.html, with a catch-all 200.html for any url that isn't a file in the build -- e.g. "/something/someData").
My static build has some .js, .map and .html files. I want all urls (catch all) to point to the index.html, except from actual build files (JS etc..). I've tried many versions of the config below, and nothing seems to be routing the way I want it aside from the default "/" route.
A route like "/something/someData" simply doesn't work and gives me a `404`.
What should my configuration look like for this? Is there a problem with Now Static builds atm?
{ "version": 2, "builds": [ { "src": "*.js", "use": "@now/static" }, { "src": "*.map", "use": "@now/static" }, { "src": "*.html", "use": "@now/static" } ], "routes": [ { "src": "/(.*)", "dest": "/index.html"}, ], }

Load previous messages

January 11, 2019 at 2:30pm

You can always check the source in deployment.now.sh/_src to see if there is a now.json there. I will relay your feedback.

  • reply
  • like

January 11, 2019 at 7:34pm
{"src": "^/(.*)", "dest": "/index.html"}

That should probably be documented somewhere more prominently, it's the (not so obvious) solution to what I would imagine is a very common problem with the popularity of client-side routing.

  • reply
  • like
like-fill
1
  • reply
  • like

From my experience this still is only a partial solution, as it requires hard-coding all other valid routes at a higher priority (otherwise all requests for CSS/JS/images/etc are also rewritten to index.html). It would be nice to just have something similar to nginx's try_files or Netlify's _redirects

Edited
  • reply
  • like

We are working on the docs about this as we speak. Also, they are open source, feel free to do a PR if you think it is a quick addition.

like-fill
1
  • reply
  • like

From my experience this still is only a partial solution, as it requires hard-coding all other valid routes at a higher priority (otherwise all requests for CSS/JS/images/etc are also rewritten to index.html). It would be nice to just have something similar to nginx's try_files or Netlify's _redirects

Agree and we are working on options. Custom 404 is also on the works.

  • reply
  • like

Log in or sign up to chat