question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to implement a fallback route for 404/NotFound

See original GitHub issue

I see closed issues related to a fallback/404 route but I can’t see how to implement it; I’m getting errors trying to use RouterSwitch

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jthoms1commented, Apr 25, 2018

@stencil/router 0.1.0 published 🎉

We have introduced a Router Switch. Please refer to the following link for how to use it. This also includes the ability to use a 404 fallback route.

  1. Import the RouterSwitch.
import { RouterSwitch } from '@stencil/router';
  1. Wrap your routes with the Switch.
<stencil-router>
    <RouterSwitch>
        <stencil-route url="/" component="landing-page" exact={true} />
        <stencil-route url="/demos" component="demos-page" />
        <stencil-route url="/other" component="other-page" />
    </RouterSwitch>
</stencil-router>
  1. Add a route as the last item in the list and do not give it a url to match on.
<stencil-router>
    <RouterSwitch>
        <stencil-route url="/" component="landing-page" exact={true} />
        <stencil-route url="/demos" component="demos-page" />
        <stencil-route url="/other" component="other-page" />
        <stencil-route component="page-not-found" />
    </RouterSwitch>
</stencil-router>

An example of the full implementation can be seen here in the stenciljs.com src. https://github.com/ionic-team/stencil-site/blob/master/src/components/stencil-site/stencil-site.tsx

0reactions
jgalleycommented, Apr 25, 2018

+1! We require a 404 route too please

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling 404 Routes in React with a Not Found component
... 404 routes in React Router and provide a fallback component for ... Let's use React Router's <Link to="/oops" /> component inside our ......
Read more >
How to implement a fallback route for 404/NotFound #34
I see closed issues related to a fallback/404 route but I can't see how to implement it; I'm getting errors trying to use...
Read more >
How to implement a standalone 404 page in React Router 6 ...
Create a single 404 not-found route and redirect to it from any nested Routes component. Example: Feature1
Read more >
Client side "404 not found" · React Router
To create a client side "404 not found" fallback all you need to do is make use of a <Route /> component with...
Read more >
React Router v4 Tutorial - #4 Switch, Redirect, & Fallback ...
Typically, a website would either spit back a 404 Not Found template, ... React Router v4 Tutorial - #4 Switch, Redirect, & Fallback...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found