Skip to content
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

Access value of the url variable #235

Open
samhaaf opened this issue Dec 14, 2022 · 3 comments
Open

Access value of the url variable #235

samhaaf opened this issue Dec 14, 2022 · 3 comments

Comments

@samhaaf
Copy link

samhaaf commented Dec 14, 2022

Hello,

I'm trying to attach some reactivity to the value in url that is passed to Router but it's never getting updated.

First question: is that url parameter even being utilized? I can refrain from passing it in and the routing behavior still works as expected.

Second question: if we pass the url as <Route bind:url={url}> will the url get updated?

Third question: if the answer to Q2 is no, can we add that behavior? It would be useful to be able to tap into that variable for reactivity. I have seen other threads about this so I know people would find it useful.

Thank you!
Sam

@krishnaTORQUE
Copy link
Collaborator

Please give a full example or minimal repo.

@mrbrianevans
Copy link
Contributor

I also tried binding to it, only to discover it doesn't work like that.
To access the current URL, you need to do this:

import { useLocation } from 'svelte-routing';
const location = useLocation();

$: console.log('Current URL path:', $location.pathname)

Its a context variable accessible in any of the components underneath the Router.

@krishnaTORQUE
Copy link
Collaborator

It suppose to work. What is wrong or problem you are facing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants