fix: redirect to root in resistant not found

proto-module-actu-react
Jalil Arfaoui 2023-05-13 23:36:01 +02:00
parent 1b25d19a0f
commit 102d73e338
3 changed files with 6 additions and 2 deletions

View File

@ -1,4 +1,5 @@
import { Resistant } from "./Resistant"; import { Resistant } from "./Resistant";
import { getResistantsPageUrl } from "./getResistantsPageUrl";
export const getResistantPageUrl = (resistant: Resistant) => export const getResistantPageUrl = (resistant: Resistant) =>
`https://www.enfance-libre.fr/#/${resistant.id}`; `${getResistantsPageUrl()}/#/${resistant.id}`;

View File

@ -0,0 +1,2 @@
export const getResistantsPageUrl = () =>
`https://www.enfance-libre.fr/resistants`;

View File

@ -1,6 +1,7 @@
import { redirect, useNavigate, useParams } from "react-router"; import { redirect, useNavigate, useParams } from "react-router";
import { getResistantPhotoUrl } from "../getResistantPhotoUrl"; import { getResistantPhotoUrl } from "../getResistantPhotoUrl";
import { resistants } from "../resistants"; import { resistants } from "../resistants";
import { getResistantsPageUrl } from "../getResistantsPageUrl";
export const PageResistant = () => { export const PageResistant = () => {
const { idResistant } = useParams(); const { idResistant } = useParams();
@ -9,7 +10,7 @@ export const PageResistant = () => {
const resistant = resistants.find((r) => r.id === idResistant); const resistant = resistants.find((r) => r.id === idResistant);
if (!resistant) { if (!resistant) {
redirect("/"); redirect(getResistantsPageUrl());
return <>Résistant introuvable</>; return <>Résistant introuvable</>;
} }