Created
September 3, 2017 02:17
-
-
Save itsdouges/cfeeeb24512d8b6bdeb80f860fea3be6 to your computer and use it in GitHub Desktop.
React Router `<Route />` that handles a not found state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
import React from 'react'; | |
import { Route } from 'react-router-dom'; | |
import NotFound from 'features/NotFound'; | |
type Props = { | |
component: any, | |
}; | |
const RouteWithNoMatch = ({ component: Component, ...props }: Props) => ( | |
<Route | |
{...props} | |
render={(router) => (router.location.state && router.location.state.notFound | |
? <NotFound /> | |
: <Component {...router} /> | |
)} | |
/> | |
); | |
export default RouteWithNoMatch; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment