Skip to content

Client-side router gives 404 on endpoints #2948

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

Closed
illright opened this issue Nov 29, 2021 · 3 comments
Closed

Client-side router gives 404 on endpoints #2948

illright opened this issue Nov 29, 2021 · 3 comments

Comments

@illright
Copy link
Contributor

Describe the bug

Endpoints aren't recognized by the client-side router as valid routes, resulting in 404 errors when a user tries to navigate to an endpoint by clicking a link or triggering a goto(). Upon a fresh request to the server (bypassing the client-side router), the request succeeds, however.

The use case for this is to allow setting cookies before redirecting, for example, to implement logout functionality.

Reproduction

https://github.com/illright/sveltekit-goto-endpoints-repro

Logs

No response

System Info

System:
    OS: Linux 5.10 Arch Linux
    CPU: (8) x64 Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
    Memory: 816.88 MB / 3.76 GB
    Container: Yes
    Shell: 3.3.1 - /bin/fish
  Binaries:
    Node: 17.1.0 - /usr/sbin/node
    npm: 8.1.3 - /usr/sbin/npm
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.3 
    @sveltejs/kit: next => 1.0.0-next.201 
    svelte: ^3.44.0 => 3.44.2

Severity

annoyance

Additional Information

No response

@Conduitry
Copy link
Member

This is the intended behavior, and changed in #2656. You can use https://kit.svelte.dev/docs#anchor-options-rel-external to force a full page reload when the link is clicked.

@illright
Copy link
Contributor Author

@Conduitry I see, thanks. Looks like this is the third such issue, perhaps it's worth mentioning this workaround in the Endpoints section? I see it mentioned in the header you've linked to, but as a user, that's not where I was searching for an answer, I was searching in the Endpoints section.

@josh-collinsworth
Copy link

josh-collinsworth commented Jan 11, 2022

There's a further wrinkle to this issue, which is: when using the static adapter (possibly when prerendering in general), unless the endpoint is explicitly called in a load function, it will 404 even with rel="external" on the anchor, presumably because the page won't be rendered by the static adapter if it's never explicitly called. Loading the endpoint in a browser results in a 404, but refreshing the page or going to the URL works just fine.

However, when I added rel="external" to the link, then the endpoint would never be generated in the first place, resulting in a different 404 (this time, one from Netlify, and again, presumably because the route was never "detected" by the static adapter).

I'm running into the same issue now with pagination on my blog: no matter what page I navigate to, the router only shows the first 10 blog posts, unless I refresh the page or navigate directly to /blog/page/x, in which case it works fine. Note that the pagination is a dynamic route, and not an endpoint.

Anyway, I mention all this because it seems there are some issues with prerendering and the router (possibly with prerendering detection) that still need to be fixed, and that cannot always be remedied simply by adding rel="external" to the link.

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

3 participants