Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Programmatic navigation #29

Closed
Rich-Harris opened this issue Dec 19, 2017 · 6 comments · Fixed by #46
Closed

Programmatic navigation #29

Rich-Harris opened this issue Dec 19, 2017 · 6 comments · Fixed by #46

Comments

@Rich-Harris
Copy link
Member

At some point we'll need to be able to do this sort of thing:

import { goto } from 'sapper/runtime/app.js';

goto('/a?b=c').then(() => {
  // navigation succeeded
});

goto('/d', { replaceState: true }).then(...)

Presumably it would only fail if the href matched some route and there was an error during preload or render.

Open question whether or not it should navigate if no route is matched (i.e. just doing window.location.href = href). I suppose probably yes.

@eldoy
Copy link

eldoy commented Aug 11, 2019

For anyone searching for how to redirect sapper applications:

import { goto } from '@sapper/app'
goto('your/path')

@quantuminformation
Copy link

Thanks for the goto, is this for non preload stuff vs the this.redirect(302, /);

@kantord
Copy link

kantord commented Jan 13, 2020

I feel like it would be super cool to have something reactive for this?

Something like being able to change window.location.href and causing a navigation in Sapper

@snowman-repos
Copy link

Unfortunately Jest fails with Cannot find module '@sapper/app' when I import { goto } from '@sapper/app' :(

@Rodrigoplp
Copy link

Is there a way to do goto('your/path', { target: '_blank' })?

@antony
Copy link
Member

antony commented Aug 11, 2020

This issue is 3 years old. To get help with goto, come and chat to us

@sveltejs sveltejs locked as resolved and limited conversation to collaborators Aug 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants