@@ -2,7 +2,7 @@ import { Trans } from '@lingui/react/macro';
22import { Banner , Flex , FlexItem } from '@patternfly/react-core' ;
33import WrenchIcon from '@patternfly/react-icons/dist/esm/icons/wrench-icon' ;
44import { type ElementType } from 'react' ;
5- import { Navigate , useLocation } from 'react-router' ;
5+ import { Navigate , redirect , useLocation } from 'react-router' ;
66import { ErrorBoundary , ExternalLink , NotFound } from 'src/components' ;
77import {
88 AboutProject ,
@@ -31,7 +31,6 @@ import {
3131 ExecutionEnvironmentRegistryList ,
3232 GroupDetail ,
3333 GroupList ,
34- LoginPage ,
3534 MultiSearch ,
3635 MyImports ,
3736 MyNamespaces ,
@@ -50,11 +49,10 @@ import {
5049 UserList ,
5150 UserProfile ,
5251} from 'src/containers' ;
53- import { StandaloneLayout } from 'src/layout' ;
5452import { Paths , formatPath } from 'src/paths' ;
5553import { config } from 'src/ui-config' ;
5654import { loginURL } from 'src/utilities' ;
57- import { useUserContext } from './user -context' ;
55+ import { useAppContext } from './app -context' ;
5856
5957interface IRouteConfig {
6058 beta ?: boolean ;
@@ -211,12 +209,6 @@ const routes: IRouteConfig[] = [
211209 path : Paths . ansible . namespace . mine ,
212210 beta : true ,
213211 } ,
214- {
215- component : LoginPage ,
216- path : Paths . meta . login ,
217- noAuth : true ,
218- beta : true ,
219- } ,
220212 {
221213 component : CollectionDocs ,
222214 path : Paths . ansible . collection . docs_page ,
@@ -301,10 +293,10 @@ const AuthHandler = ({
301293 noAuth,
302294 path,
303295} : IRouteConfig ) => {
304- const { credentials } = useUserContext ( ) ;
296+ const { user } = useAppContext ( ) ;
305297 const { pathname } = useLocation ( ) ;
306298
307- if ( ! credentials && ! noAuth ) {
299+ if ( ! user . username && ! noAuth ) {
308300 // NOTE: also update LoginLink when changing this
309301 if ( config . UI_EXTERNAL_LOGIN_URI ) {
310302 window . location . replace ( loginURL ( pathname ) ) ;
@@ -358,16 +350,32 @@ const appRoutes = () =>
358350 ...rest ,
359351 } ) ) ;
360352
353+ const convert = ( m ) => {
354+ const {
355+ default : Component ,
356+ clientLoader : loader ,
357+ clientAction : action ,
358+ ...rest
359+ } = m ;
360+ return { ...rest , loader, action, Component } ;
361+ } ;
362+
361363export const dataRoutes = [
362364 {
363- element : < StandaloneLayout /> ,
365+ id : 'root' ,
366+ lazy : ( ) => import ( 'src/routes/root' ) . then ( ( m ) => convert ( m ) ) ,
364367 children : [
365368 {
366369 errorElement : < ErrorBoundary /> ,
367370 children : [
368371 {
369372 index : true ,
370- element : < Navigate to = { formatPath ( Paths . core . status ) } /> ,
373+ loader : ( ) => redirect ( formatPath ( Paths . core . status ) ) ,
374+ } ,
375+ {
376+ path : 'login' ,
377+ id : 'login' ,
378+ lazy : ( ) => import ( 'src/routes/login' ) . then ( ( m ) => convert ( m ) ) ,
371379 } ,
372380 ...appRoutes ( ) ,
373381 // "No matching route" is not handled by the error boundary.
0 commit comments