How to use goto in a Svelte module? "goto is not a function"
See original GitHub issueHi,
I’m coding a module with some functions to be used elsewhere and I’m having trouble to use goto, here some example:
functions.svelte
<script context="module">
import { goto } from "@roxi/routify";
export function doSomething() {
console.log("did it");
goto("/newpage");
}
</script>
After that, I import the function in my App:
<script>
import { doSomething } from "./functions.svelte";
doSomething();
</script>
When running, I get the error “goto is not a function”
What is the proper way to do this?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
`svelte-kit package` cannot include `goto` function from `$app ...
Everything works just fine in dev. I import the Select component I created into my project. However, when the app is build and...
Read more >Cannot use goto on the server : r/sveltejs - Reddit
I want to redirect the user to the login page if they are not logged in, but for some reason it gives out...
Read more >Going back to the previous page with 'goto' / Sveltekit navigation
in our SvelteKit project we are sometimes navigating to previous page like in the example bellow import { goto } from '$app/navigation'; ...
Read more >Modules • Docs • SvelteKit
Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) to the specified url ....
Read more >Authentication in Svelte using cookies - LogRocket Blog
Create a Svelte app using SvelteKit that implements a cookie for ... SvelteKit provides its own function for client-side navigation: goto .
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hum, I tried using window.location.href, but it loses data on stores (unless saved on browser, what I’m not inclined to do), guess I will need to move goto to the page.
Thanks anyway.
@ferulisses if you don’t need dynamic redirects, you can also use this:
redirect
redirects before component is loadedrewrite
same as redirect, but preserves the URLYou can also create guards with
beforeUrlChange
.For
context="module"
guards you will have to wait for Routify 3, which we hope to release a preview of very soon.