0

I want to let users access specific pages when typing in for example www.page-url.com/about-us instead of going via www.page-url.com and then choose about us in the nav bar. When I type in www.page-url.com/about-us, I get a 404 error (page not found). How can this action be prevented? I have tried different solutions from questions here on SO, but none of them worked.

Router code:

<Router >
        <MobileNavbar />
        <Navbar />
        <Switch>
          <Route path='/' exact component={Home} />
          <Route path='/om-oss' component={AboutUs} />
          <Route path='/sponsorar' component={Sponsor} />
          <Route path='/bli-sponsor' component={BecomeSponsor} />
          <Route path='/bli-medlem' component={BecomeMember} />
          <Route path='/admin' exact component={Admin} />
          <Route path='/admin-login' exact component={AdminLogin} />
          <Route path="/admin/bytt-passord" exact component={ChangeCreds} />
          <Route path="/admin/medlemer" exact component={Members} />
          <Route path="/til-foreldre" component={Parents} />
          <Route path="/kalendar" component={Calendar} />
          <Route path="/admin/kalendar" exact component={AdminCalendar} />
        </Switch>
        <Footer />
      </Router>
Daniel Olsen
  • 412
  • 4
  • 15
  • How is your app hosted? If you are using nginx, you have to configure your server to point the request to your SPA index html – Ari Seyhun Jun 01 '21 at 08:21
  • Do you want to prevent showing 404 error pages? In your current router configs, please take an example – TopW3 Jun 01 '21 at 08:24
  • I host my app via Firebase hosting to a domain bought here in Norway. I want to let users access for example the About us-page with typing in www.page-url.com/about-us, but when I do this, I get a 404 page not found-error. – Daniel Olsen Jun 01 '21 at 08:31
  • you are getting the 404 error because it don't see any route which is matching the path `/about-us` – Shyam Jun 01 '21 at 08:48

1 Answers1

0

When the user types some route which you are not supporting then you can have a catch all Route. Add this at the bottom of your Switch .

<Route path='*'><SomeComponent /></Route>

Catch All Routes

Shyam
  • 5,292
  • 1
  • 10
  • 20