'Redirect to 404 page if url is incorrect or if a 404 error is got from BE

I need to redirect to a custom page in case if the entered URl does not exist or in case if I receive a 404 error from BE. To catch the BE error I do a navigation in the Interceptor to the /error page, but how I should proceed with the incorrect URL?

This is what I did:

  <IntlProvider translations={translations} locale={locale}>
      <Router>
        <Switch>
          <Route path="/error" component={CustomErrorPage} />
          <Route exact path="*" component={CustomErrorPage} />
          <PrivateRoute path="/" component={Main} />
        </Switch>
      </Router>
    </IntlProvider>

PrivateRoute checks if the user is logged in. If anybody has an advice it will be nice. Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source