Skip to content
This repository has been archived by the owner on Apr 12, 2020. It is now read-only.

Wildcard route declared last catches all routes #8

Closed
n1313 opened this issue May 5, 2019 · 6 comments
Closed

Wildcard route declared last catches all routes #8

n1313 opened this issue May 5, 2019 · 6 comments
Labels
svelte-dependent Something that should be fixed on Svelte itself

Comments

@n1313
Copy link
Contributor

n1313 commented May 5, 2019

I am trying to setup a configuration where URLs with no matching route would display a NotFoundPage component. It looks like the wildcard route should help me achieve this, but I find its behaviour confusing.

The following setup displays NotFoundPage for pathname / (and for every other pathname as well), so there is no way to access HomePage:

<Router>
  <Route path="/" component={HomePage} />
  <Route path="*" component={NotFoundPage} />
</Router>

If I reverse the order in which my routes are declared, then I get what I need. The following setup displays HomePage for pathname / and NotFoundPage for everything else:

<Router>
  <Route path="*" component={NotFoundPage} />
  <Route path="/" component={HomePage} />
</Router>

It feels weird having to declare 404 as the first item of my router, above my index page. Am I doing something wrong, or is this the intended behaviour?

I'm using svelte 3.2.0 and svero 0.2.4, Firefox 66 OSX.

@kazzkiq
Copy link
Owner

kazzkiq commented May 6, 2019

There is nothing wrong with your code.

It seems it's a Svelte quirk at the moment that makes sibling components render in reverse order. Check sveltejs/svelte#2281.

Edit: fixed Svelte Issue link.

@n1313
Copy link
Contributor Author

n1313 commented May 7, 2019

Thank you for the explanation! I will monitor the issue you linked and will update here when the problem is fixed.

@EmilTholin
Copy link

I think the wrong link was posted here. I believe you want to monitor this.

@kazzkiq
Copy link
Owner

kazzkiq commented May 7, 2019

You're right! Updated link in my comment to prevent further confusion.

@kazzkiq kazzkiq added the svelte-dependent Something that should be fixed on Svelte itself label May 7, 2019
@pateketrueke
Copy link
Contributor

pateketrueke commented Jul 25, 2019

Hi @n1313 recently we released a major version of svero aiming to solve many issues/features, in that update * behavior was changed, also a fallback keyword was added to serve as this purpose.

Also, it was built on top a routing module that order-and-match your routes based on depth and complexity, so in your example both cases are exactly the same now.

Please let us know if this works for you.

@kazzkiq kazzkiq closed this as completed in d11a3ff Nov 1, 2019
@kazzkiq kazzkiq reopened this Nov 1, 2019
@kazzkiq
Copy link
Owner

kazzkiq commented Apr 12, 2020

Svero is now deprecated. Check #68 for alternatives.

@kazzkiq kazzkiq closed this as completed Apr 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
svelte-dependent Something that should be fixed on Svelte itself
Projects
None yet
Development

No branches or pull requests

4 participants