poshaughnessy
poshaughnessy

Reputation: 2028

Svelte/Sapper dynamic client-side routing

I'm using Svelte and Sapper for a web app where I need to proceed to the next page dynamically, i.e. after something happens (a Web Bluetooth connection) - not just from an <a> element click.

For <a> links, Sapper intercepts these and performs client-side routing. How can I achieve client-side routing myself, via JavaScript?

If, for example, I call location.href = ... then this is not intercepted and it involves a roundtrip to the server for the next page.

Is there a neat way of doing this? (Something like router.route('/my-page'))?

Upvotes: 6

Views: 2653

Answers (2)

Yousuf Iqbal Hashim
Yousuf Iqbal Hashim

Reputation: 975

For Svelte-3:

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

Upvotes: 7

poshaughnessy
poshaughnessy

Reputation: 2028

I found it here in the docs:

import { goto } from 'sapper/runtime.js';
goto('/my-page');

Upvotes: 8

Related Questions