Skip to content

Instantly share code, notes, and snippets.

@itsdouges
Created September 3, 2017 02:17
Show Gist options
  • Save itsdouges/cfeeeb24512d8b6bdeb80f860fea3be6 to your computer and use it in GitHub Desktop.
Save itsdouges/cfeeeb24512d8b6bdeb80f860fea3be6 to your computer and use it in GitHub Desktop.
React Router `<Route />` that handles a not found state
// @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