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.

Handle not found pages gracefully

See original GitHub issue

Hi.

I apologize if I bring it up as a duplicate, but I’ve gone through all related issues and haven’t found a solution.

Expected behavior

I want to be able to control “not found” route behavior and render a dedicated react component (page) in that case. This is how I would expect it to work:

// routes.js
import { mount, route } from 'navi'
import Frontpage from './pages/Frontpage'
import About from './pages/About'
import Page404 from './pages/Page404'

export default mount({
  '/': route({ view: <Frontpage /> }),
  '/about': route({ view: <About /> }),
  '*': route({ view: <Page404 /> }),
})
// App.jsx
import React, { Suspense } from 'react'
import ReactDOM from 'react-dom'
import { Router, View } from 'react-navi'
import routes from './routes'

const render = module.hot ? ReactDOM.hydrate : ReactDOM.render

render(
  <Router routes={routes}>
    <Suspense fallback={null}>
      <View />
    </Suspense>
  </Router>,
  document.getElementById('root'),
)

Current behavior

The route associated with the “*” wildcard doesn’t render. Instead, I get a blank page and the following client-side error:

Uncaught NotFoundError: URL not found: /abouts
    at createNotFoundChunk (webpack-internal:///./node_modules/navi/dist/es/Chunks.js:27:16)
    at eval (webpack-internal:///./node_modules/navi/dist/es/createChunksMatcher.js:54:110)
    at step (webpack-internal:///./node_modules/navi/dist/es/createChunksMatcher.js:28:23)
    at Object.eval [as next] (webpack-internal:///./node_modules/navi/dist/es/createChunksMatcher.js:9:53)
    at eval (webpack-internal:///./node_modules/navi/dist/es/Matcher.js:55:29)
    at step (webpack-internal:///./node_modules/navi/dist/es/Matcher.js:27:23)
    at Object.eval [as next] (webpack-internal:///./node_modules/navi/dist/es/Matcher.js:8:53)
    at step (webpack-internal:///./node_modules/navi/dist/es/createChunksMatcher.js:13:139)
    at Object.eval [as next] (webpack-internal:///./node_modules/navi/dist/es/createChunksMatcher.js:9:53)
    at eval (webpack-internal:///./node_modules/navi/dist/es/Matcher.js:55:29)

Another error specifies that the previous one has originated from the View I have:

The above error occurred in the <View> component:
    in View
    in Suspense
    in HashScroll (created by NaviProvider)
    in NaviProvider (created by Router)
    in Router

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
jamesknelsoncommented, Jul 23, 2019

@kettanaito, is there any reason that <NotFoundBoundary> won’t work for you?

https://frontarm.com/navi/en/reference/react-components-hooks/#notfoundboundary

0reactions
jamesknelsoncommented, Jul 25, 2019

Not at the moment, unfortunately. It might be worth opening an issue on create react app, as I feel like showing an error screen even on handled errors is an issue there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fail Gracefully: Building Your Custom 404 Error Page
It is unfortunate, but when visitors come across a “404 Not Found” page, most do not try to find the content elsewhere on...
Read more >
Handling 404 Not Found in Asp.Net Core - DevTrends
Handling specific cases of page not found is best addressed with a custom view and setting the status code (either directly or via...
Read more >
How to handle 404 errors in ASP.NET Core MVC
A simple solution is to check for the HTTP status code 404 in the response. If found, you can redirect the control to...
Read more >
Custom 404 and 500 Error Pages in Rails
Now if any record or page doesn't exist, the new page will handle it gracefully. Happy handling! Solutions for Updating ActiveStorage ...
Read more >
node.js - How to redirect 404 errors to a page in ExpressJS?
This will override the default page-not-found error page: ... httpError(404) ); // Handle all unhandled errors: app.use( handler );.
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