From ad0e409448644c22494f52623ad964caedaa6caa Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Tue, 9 Apr 2019 10:39:47 -0400 Subject: [PATCH] do 404 modal redirect on unknown routes --- src/components/NotifyAndRedirect.jsx | 42 +++++++++++++++++++ src/index.jsx | 28 ++++++++----- .../screens/Organization/Organization.jsx | 2 + 3 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 src/components/NotifyAndRedirect.jsx diff --git a/src/components/NotifyAndRedirect.jsx b/src/components/NotifyAndRedirect.jsx new file mode 100644 index 0000000000..11e286dae8 --- /dev/null +++ b/src/components/NotifyAndRedirect.jsx @@ -0,0 +1,42 @@ +import React, { Component } from 'react'; + +import { Redirect, withRouter } from 'react-router-dom'; + +import { Trans } from '@lingui/macro'; + +import { withRootDialog } from '../contexts/RootDialog'; + +class NotifyAndRedirect extends Component { + constructor (props) { + super(props); + + const { setRootDialogMessage, location } = this.props; + setRootDialogMessage({ + title: '404', + bodyText: ( + + Cannot find route + {` ${location.pathname}`} + . + + ), + variant: 'warning' + }); + } + + render () { + const { to, push, from, exact, strict, sensitive } = this.props; + return ( + + ); + } +} + +export default withRootDialog(withRouter(NotifyAndRedirect)); diff --git a/src/index.jsx b/src/index.jsx index 9f542327a5..59b857cd49 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -20,6 +20,7 @@ import './components/SelectedList/styles.scss'; import { Config } from './contexts/Config'; import Background from './components/Background'; +import NotifyAndRedirect from './components/NotifyAndRedirect'; import RootProvider from './RootProvider'; import App from './App'; @@ -220,17 +221,22 @@ export async function main (render) { }, ]} render={({ routeGroups }) => ( - routeGroups - .reduce((allRoutes, { routes }) => allRoutes.concat(routes), []) - .map(({ component: PageComponent, path }) => ( - ( - - )} - /> - )) + + {routeGroups + .reduce((allRoutes, { routes }) => allRoutes.concat(routes), []) + .map(({ component: PageComponent, path }) => ( + ( + + )} + /> + )) + .concat([ + + ])} + )} /> )} diff --git a/src/pages/Organizations/screens/Organization/Organization.jsx b/src/pages/Organizations/screens/Organization/Organization.jsx index e58d8903b8..2ba53ece98 100644 --- a/src/pages/Organizations/screens/Organization/Organization.jsx +++ b/src/pages/Organizations/screens/Organization/Organization.jsx @@ -17,6 +17,7 @@ import { withNetwork } from '../../../../contexts/Network'; import Tabs from '../../../../components/Tabs/Tabs'; import Tab from '../../../../components/Tabs/Tab'; +import NotifyAndRedirect from '../../../../components/NotifyAndRedirect'; import OrganizationAccess from './OrganizationAccess'; import OrganizationDetail from './OrganizationDetail'; @@ -175,6 +176,7 @@ class Organization extends Component { /> )} /> + {organization && } {error ? 'error!' : ''} {loading ? 'loading...' : ''}