Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Svelte/Sapper dynamic client-side routing

Tags:

svelte

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'))?

like image 787
poshaughnessy Avatar asked Jun 27 '18 09:06

poshaughnessy


2 Answers

For Svelte-3:

import { goto } from '@sapper/app'
goto('/profiles')
like image 23
Yousuf Iqbal Hashim Avatar answered Oct 11 '22 02:10

Yousuf Iqbal Hashim


I found it here in the docs:

import { goto } from 'sapper/runtime.js';
goto('/my-page');
like image 175
poshaughnessy Avatar answered Oct 11 '22 03:10

poshaughnessy