-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
issuing a goto('/route') to an internal svelte page that redirects to an external url throws an "Error: Not found: /api/user" error #9399
Comments
Just wanted to add I ran into the same error message while trying to call
The url I passed in looked like For me It broke on |
I can confirm this problem even when using
A temporary solution is to use |
and as @zyxd suggested I'm using // see issue: https://github.com/sveltejs/kit/issues/9399#issuecomment-1466109848
const goto = (url: string) => (window.location.href = url); |
I found out that the problem arises given the following conditions:
please have a look at the updated issue and sample project |
In the docs it tells you to use goto only for internal routes, and use window.location.href for external one, the problem with my example is that it is an internal route that redirect to an external route, and sveltekit treats it as an internal one anyway is using goto. |
I was thinking that perhaps an easier approach would be to make |
I can confirm that this issue is solved in @sveltejs/[email protected] - #9391 |
I believe I'm seeing this issue again, with Svelte version 4.0.5 and SvelteKit 1.22.3. Calling Am I holding it wrong? Would it be helpful to create a reproduction or is the team aware? Let me know how I can be helpful, thanks! CleanShot.2023-07-21.at.10.03.52.mp4 |
Having also this issue. My solution is simply to calculate the URL in the API but to not redirect from that API. Instead I just return the URL to the client with a |
Describe the bug
When issuing a
goto('/redirect)
to an internal route handled by an+page.ts
that redirects to an external url, throws external url throws an "Error: Not found: /api/user" errorNote: te docs says
But in this case I'm navigating to an internal url (
/redirect
). The problem is that/redirect
redirect to an external url (https://www.google.com
) but sveletkit tries to handle it like if it were an internal one. Sveltekit should recognize it's external and just redirect user.Note: you need to have the inspector (F12) open to see the error
The debugger then stops in the following line
It seems like svelkit can't recognize an external url (in thi case
https://www.google.com
) and tries to handle it using the defined routes, when it can't find it it throws an errorExpected behaviour
Sveltekit should recognize when an internal route (+page.ts, +page.server.ts, +server.ts) is redirecting user to an external url and stop trying to process it.
Note this is happening with the following version:
"@sveltejs/kit": "^1.5.0"
"svelte": "^3.54.0",
With version
"@sveltejs/kit": "^1.10.0",
"svelte": "^3.54.0",
it worked ok
Reproduction
this github repo has a complete example: https://github.com/opensas/goto-api-route-svelte-issue
you can open it in gitpod with: https://gitpod.io/#https://github.com/opensas/goto-api-route-svelte-issue
create a new project
put thin into src/routes/+page.svelte
and this in
/routes/redirect/+page.ts
(same issue happens with a+page.server.ts
or a+server.ts
api route)start the project
navigate to http://localhost:5173/
open debugger (F12)
click on the
goto('/redirect')
buttonError: Not found: /api/user
An error occurred while loading the page. This will cause a full page reload. (This message will only appear during development.)
Logs
System Info
Severity
there's a workaround (
window.location.href = 'external_url'
), but you have to be aware that an internal route ('/redirect') is redirecting to an external one to avoid usinggoto
)Additional Information
github repo: https://github.com/opensas/goto-api-route-svelte-issue
running example at https://gitpod.io/#https://github.com/opensas/goto-api-route-svelte-issue
The text was updated successfully, but these errors were encountered: