mefechoel / svelte-navigator

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

Conditional routes #27

Closed quantuminformation closed 3 years ago

quantuminformation commented 3 years ago

Is this something evil or can it be supported?

            {#if $userDataStore}
                <Route path="/" component="{Home}" />
            {:else}
                <Route path="/" component="{Feed}" />
            {/if}
mefechoel commented 3 years ago

This should just work... The Router runs the matching everytime the location or the registered routes change, so it's fine... Or does the example not work?

quantuminformation commented 3 years ago

wasnt working, ill double check tomorrow

mefechoel commented 3 years ago

Alright, I'll have to check to. In the meantime you could do it like this:

<Route path="/">
  {#if $userDataStore}
    <Home />
  {:else}
    <Feed />
  {/if}
</Route>
mefechoel commented 3 years ago

I could nor reproduce the issue... I've set up a small example in the REPL, which uses both the Route's component prop and the Route children for rendering the views and both work just fine... Could you provide an example where it does not work?

quantuminformation commented 3 years ago
{#if $userDataStore} {:else} {/if}

works!

sorry i've been busy