-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NotFound component and 404 redirect (#440)
* Add NotFound component and 404 redirect * fix TS * use theme colors and fix catch-all path for MemoryRouter
- Loading branch information
Showing
5 changed files
with
99 additions
and
41 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from "react"; | ||
import Box from "@mui/material/Box"; | ||
import Typography from "@mui/material/Typography"; | ||
|
||
export function NoEnvironmentSelected() { | ||
return ( | ||
<Box | ||
sx={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
height: "100%" | ||
}} | ||
data-testid="no-environment-selected" | ||
> | ||
<Typography sx={{ fontSize: "18px", color: "secondary.dark" }}> | ||
Select an environment to show details | ||
</Typography> | ||
</Box> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from "react"; | ||
import Box from "@mui/material/Box"; | ||
import Typography from "@mui/material/Typography"; | ||
|
||
export function NotFound() { | ||
return ( | ||
<Box | ||
sx={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
height: "100%" | ||
}} | ||
> | ||
<Typography | ||
variant="h1" | ||
sx={{ fontSize: "18px", color: "secondary.dark" }} | ||
> | ||
404 - Not found | ||
</Typography> | ||
</Box> | ||
); | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,58 @@ | ||
import React from "react"; | ||
import { useHref, Navigate } from "react-router-dom"; | ||
|
||
import { PageLayout } from "./layouts"; | ||
import { EnvironmentDetails } from "./features/environmentDetails"; | ||
import { EnvironmentCreate } from "./features/environmentCreate"; | ||
import { NoEnvironmentSelected } from "./components/NoEnvironmentSelected"; | ||
import { NotFound } from "./components/NotFound"; | ||
|
||
/** | ||
* Define URL routes for the single page app | ||
*/ | ||
|
||
export const routes = [ | ||
{ | ||
path: "/", | ||
element: <PageLayout />, | ||
children: [ | ||
{ | ||
path: ":namespaceName/new-environment", | ||
element: <EnvironmentCreate /> | ||
}, | ||
{ | ||
path: ":namespaceName/:environmentName", | ||
element: <EnvironmentDetails /> | ||
} | ||
] | ||
} | ||
]; | ||
const HardRedirectNotFound = () => { | ||
// useHref takes into account React Router basename option. So if basename is | ||
// set to "/conda-store", the hook will return "/conda-store/not-found" | ||
const url = useHref("/not-found"); | ||
window.location.replace(url); | ||
return null; | ||
}; | ||
|
||
export function createRoutes(routerType: "browser" | "memory") { | ||
return [ | ||
{ | ||
path: "/", | ||
element: <PageLayout />, | ||
children: [ | ||
{ | ||
index: true, | ||
element: <NoEnvironmentSelected /> | ||
}, | ||
{ | ||
path: ":namespaceName/new-environment", | ||
element: <EnvironmentCreate /> | ||
}, | ||
{ | ||
path: ":namespaceName/:environmentName", | ||
element: <EnvironmentDetails /> | ||
}, | ||
{ | ||
path: "not-found", | ||
element: <NotFound /> | ||
} | ||
] | ||
}, | ||
// If no route matches, send the user to a route on the server that will | ||
// return a proper 404 HTTP status code. | ||
{ | ||
path: "*", | ||
element: | ||
routerType === "browser" ? ( | ||
<HardRedirectNotFound /> | ||
) : ( | ||
<Navigate to="/not-found" replace={true} /> | ||
) | ||
} | ||
]; | ||
} |