Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL set to /404.html even though routing works #116

Open
plasmatech8 opened this issue May 31, 2021 · 3 comments
Open

URL set to /404.html even though routing works #116

plasmatech8 opened this issue May 31, 2021 · 3 comments

Comments

@plasmatech8
Copy link

I was trying out some Svelte routers.

I decided to try testing the Vite Svelte template using the sample project from the svelte-spa-router repo (a different router).

Then I tried converting this example project from svelte-spa-router to svelte-router-spa.

The result is:

However, URL path keeps getting set to /404.html. Any ideas why?

image

@jorgegorka
Copy link
Owner

jorgegorka commented May 31, 2021

Hi @plasmatech8

You don't need these lines: https://github.com/plasmatech8/svelte-practice/blob/main/06_svelte-spa-router_examples/basic-routing-using-svelte-router-spa-instead/src/routes.js#L17-L20

Named params are optional so a route like: '/wild/:card' will serve both /wild and /wild/some-info

Also in line 14 https://github.com/plasmatech8/svelte-practice/blob/main/06_svelte-spa-router_examples/basic-routing-using-svelte-router-spa-instead/src/routes.js#L14 As all named params are optional by default there is no need to use ?

To be more specific: A route like this one https://github.com/plasmatech8/svelte-practice/blob/main/06_svelte-spa-router_examples/basic-routing-using-svelte-router-spa-instead/src/routes.js#L13-L16 will serve all this urls:

/hello
/hello/first-param
/hello/first-param/second-param

Hope that helps.

@plasmatech8
Copy link
Author

plasmatech8 commented May 31, 2021

@jorgegorka thanks for the comment :)

I am still not sure why it is changing the path to /404.html though.

Perhaps something to do with Vite. Or an issue with how the router handles anchor tags / routing. Not sure.

  • <Navigate to="/does/not/exist">Not found</Navigate> component works (but only from within the routes/router, not in the higher-level components)
  • Typing the URL path directly in the address bar works
  • <a href="/something">something</a> appears to navigate correctly, but erroneously changes the path to /404.html
  • <button on:click={() => navigateTo('/wild/dafasdf')}>asdasd</button> appears to not navigate, and erroneously changes the path to /404.html

@jorgegorka
Copy link
Owner

jorgegorka commented Jun 1, 2021

I haven't tried Vite yet

@jorgegorka thanks for the comment :)

I am still not sure why it is changing the path to /404.html though.

Perhaps something to do with Vite. Or an issue with how the router handles anchor tags / routing. Not sure.

* `<Navigate to="/does/not/exist">Not found</Navigate>` component works (but only from within the routes/router, not in the higher-level components)

You need to add the router at the very beginning of your application otherwise it would be unable to route urls correctly.
https://github.com/jorgegorka/svelte-router#usage

If you have something like:

<MainAPP>
<Header/>
<Sidebar/>
<Router {routes} />
<Footer />
</MainApp>

Then Header, Sidebar and Footer will know nothing about routes. They should all be rendered in a template inside <Router />.

In this application you can see an example with plenty of routes:

https://github.com/jorgegorka/demanda/blob/master/frontend/src/App.svelte
https://github.com/jorgegorka/demanda/blob/master/frontend/src/routes.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants