mefechoel / svelte-navigator

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

export let path not working #77

Closed tofsjonas closed 2 years ago

tofsjonas commented 2 years ago

If I do this (like in the example here: useResolve):

<Route path="foo/*" component={SomeComponent} />

And then, inside SomeComponent:

export let path: any
console.log(path)

I get this i the console:

path undefined
mefechoel commented 2 years ago

The route component does not forward the path to its component children you can either pass anonther prop to the route and call it something other than path or render your component inside the routers slot and also pass it the path like so:

<Route path="foo/*">
  <SomeComponent path="foo/*" />
</Route>
tofsjonas commented 2 years ago

Ok, thanks.

I stumbled on what I wanted by doing:

const location = useLocation()
const resolve = useResolve()
let root = resolve('', $location)

😊