AlexxNB / tinro

Highly declarative, tiny, dependency free router for Svelte's web applications.
MIT License
675 stars 30 forks source link

Further instructions on how to use 'meta' needed #58

Closed kane81 closed 3 years ago

kane81 commented 3 years ago

Hi

according to the readme you can access meta data using the following code

<script>
    import {meta} from 'tinro';
    const route = meta();  
</script>

I however cannot seem to get this code to work... I have added it to my App.svelte and I get an error

Uncaught TypeError: Cannot read property 'meta' of undefined
    at g (tinro_lib.js:1)
    at instance (App.svelte:12)
    at init (index.mjs:1474)
    at new App (App.svelte:48)
    at main.js:3
    at main.js:8

I have added the code into the repl example and get Cannot read property 'meta' of undefined

can you please add more guidance on how to init this property so we do not get this error. I have tried putting it in onMount() of App.svelte too and get the same error.

Thank you

OysterD3 commented 3 years ago

You need to use it in the component that wrap with <Route></Route>

AlexxNB commented 3 years ago

Yes, @OysterD3 is right. Most meta info is route specific, that is why it should be involved only from a child component of any <Route>. But, I think more explicit error message should helps to use meta in the right way. I'll add it.

AlexxNB commented 3 years ago

If you need none-route specific data like path, hash or query use router subscription or route.location methods.