pateketrueke / yrv

Your routing vibes! (for Svelte)
https://svelte.dev/repl/0f07c6134b16432591a9a3a0095a80de
161 stars 9 forks source link

Example of <Routers> spread across components? #42

Closed tyteen4a03 closed 4 years ago

tyteen4a03 commented 4 years ago

I have this setup:

App.svelte:

<main>
    <Navbar />
    <div class="master-container {extraClassesString}">
        <Router>
            <Route exact path="/" component={IndexPage} />
            <Route path="/blog" component={BlogListPage} />
            <Route fallback component={NotFoundPage} />
        </Router>
    </div>
</main>

BlogListPage.svelte

    ... some common header stuff
    <Router path="/blog">
        <Route exact path="/:year/:id" let:router>{router.params.year} {router.params.id}</Route>
    </Router>

Can you provide an example of how to make this routing configuration work?

pateketrueke commented 4 years ago

The <Router /> used in BlogListPage.svelte should not have path, as it is taken from the route where it was mounted.

Example: https://svelte.dev/repl/c778f2efafa44e2d8ab2556fbcb66518?version=3.20.1

Your current setup would work if you use a link like /blog/blog/1/2 — because you declared the same path twice.