mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 01:47:35 -02:30
do 404 modal redirect on unknown routes
This commit is contained in:
42
src/components/NotifyAndRedirect.jsx
Normal file
42
src/components/NotifyAndRedirect.jsx
Normal file
@@ -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: (
|
||||||
|
<Trans>
|
||||||
|
Cannot find route
|
||||||
|
<strong>{` ${location.pathname}`}</strong>
|
||||||
|
.
|
||||||
|
</Trans>
|
||||||
|
),
|
||||||
|
variant: 'warning'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render () {
|
||||||
|
const { to, push, from, exact, strict, sensitive } = this.props;
|
||||||
|
return (
|
||||||
|
<Redirect
|
||||||
|
to={to}
|
||||||
|
push={push}
|
||||||
|
from={from}
|
||||||
|
exact={exact}
|
||||||
|
strict={strict}
|
||||||
|
sensitive={sensitive}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default withRootDialog(withRouter(NotifyAndRedirect));
|
||||||
@@ -20,6 +20,7 @@ import './components/SelectedList/styles.scss';
|
|||||||
import { Config } from './contexts/Config';
|
import { Config } from './contexts/Config';
|
||||||
|
|
||||||
import Background from './components/Background';
|
import Background from './components/Background';
|
||||||
|
import NotifyAndRedirect from './components/NotifyAndRedirect';
|
||||||
|
|
||||||
import RootProvider from './RootProvider';
|
import RootProvider from './RootProvider';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
@@ -220,17 +221,22 @@ export async function main (render) {
|
|||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
render={({ routeGroups }) => (
|
render={({ routeGroups }) => (
|
||||||
routeGroups
|
<Switch>
|
||||||
.reduce((allRoutes, { routes }) => allRoutes.concat(routes), [])
|
{routeGroups
|
||||||
.map(({ component: PageComponent, path }) => (
|
.reduce((allRoutes, { routes }) => allRoutes.concat(routes), [])
|
||||||
<Route
|
.map(({ component: PageComponent, path }) => (
|
||||||
key={path}
|
<Route
|
||||||
path={path}
|
key={path}
|
||||||
render={({ match }) => (
|
path={path}
|
||||||
<PageComponent match={match} />
|
render={({ match }) => (
|
||||||
)}
|
<PageComponent match={match} />
|
||||||
/>
|
)}
|
||||||
))
|
/>
|
||||||
|
))
|
||||||
|
.concat([
|
||||||
|
<NotifyAndRedirect key="redirect" to="/" />
|
||||||
|
])}
|
||||||
|
</Switch>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import { withNetwork } from '../../../../contexts/Network';
|
|||||||
|
|
||||||
import Tabs from '../../../../components/Tabs/Tabs';
|
import Tabs from '../../../../components/Tabs/Tabs';
|
||||||
import Tab from '../../../../components/Tabs/Tab';
|
import Tab from '../../../../components/Tabs/Tab';
|
||||||
|
import NotifyAndRedirect from '../../../../components/NotifyAndRedirect';
|
||||||
|
|
||||||
import OrganizationAccess from './OrganizationAccess';
|
import OrganizationAccess from './OrganizationAccess';
|
||||||
import OrganizationDetail from './OrganizationDetail';
|
import OrganizationDetail from './OrganizationDetail';
|
||||||
@@ -175,6 +176,7 @@ class Organization extends Component {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
{organization && <NotifyAndRedirect to={`/organizations/${match.params.id}/details`} />}
|
||||||
</Switch>
|
</Switch>
|
||||||
{error ? 'error!' : ''}
|
{error ? 'error!' : ''}
|
||||||
{loading ? 'loading...' : ''}
|
{loading ? 'loading...' : ''}
|
||||||
|
|||||||
Reference in New Issue
Block a user