mefechoel / svelte-navigator

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

how do you handle 404 #44

Open giosifelis opened 2 years ago

giosifelis commented 2 years ago

How do you do a 404 page for routes that don't exist?

I"ve tried a Route with no path (just as svelte-routing suggest) with no success

<Router>
  <Route path="blog">
    <Blog />
  </Route>
  <!-- ... the rest of your routes -->
  <Route>
    <!-- Your 404 component -->
    <NotFound />
  </Route>
</Router>

any idea?

iluuu1994 commented 2 years ago

Try using a wildcard: <Route path="*">...</Route>.

eslym commented 1 year ago

this is how i do in my project, not very perfect but works well

<Route path="/customers/:id/*" let:params>
    {#await pb.records.getOne('customers', params.id) then record}
        <Router>
            <Route path="/">
                <ViewCustomer {record}/>
            </Route>
            <Route>
                <NotFound/>
            </Route>
        </Router>
    {:catch error}
        <NotFound/>
    {/await}
</Route>