mefechoel / svelte-navigator

Simple, accessible routing for Svelte
Other
502 stars 39 forks source link

how to send variable to Link #51

Closed bobwatcherx closed 2 years ago

bobwatcherx commented 2 years ago

i want send params from my variable

localhost:3000/details/myparams

example

<script>

let id = "myparams"
</script
            <Link to="details/" **+ id** >details</Link> // id is my params  ->  localhost:3000/details/myparams

<Route path="details/id" component={Details}></Route>

my Details.Vue

<script>
    import {useParams} from 'svelte-navigator'
    let params = useParams()
</script>

detaiks aja {params.id}
mefechoel commented 2 years ago

You need to define your route as

<Route path="details/:id" component={Details}></Route>

In your snippet, the : in :id was missing. Then you can access them like so:

<script>
    import { useParams } from 'svelte-navigator'
    let params = useParams()
</script>

<!-- Don't forget the "$" to access the current store value -->
{$params.id}