From dc3a56b851a6f9e51c5afe393fcd110f1961c11d Mon Sep 17 00:00:00 2001 From: Neil Murphy Date: Fri, 7 Feb 2025 02:29:07 +0000 Subject: [PATCH] always route the user to the complete path ensuring that all sub languages and all snippets slugified strings are included in the uri --- src/AppRouter.tsx | 4 ++++ src/contexts/AppContext.tsx | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/AppRouter.tsx b/src/AppRouter.tsx index 200d25a1..a18656dd 100644 --- a/src/AppRouter.tsx +++ b/src/AppRouter.tsx @@ -9,6 +9,10 @@ const AppRouter = () => { }> } /> } /> + } + /> } diff --git a/src/contexts/AppContext.tsx b/src/contexts/AppContext.tsx index 4ebd3bea..f9a88d0d 100644 --- a/src/contexts/AppContext.tsx +++ b/src/contexts/AppContext.tsx @@ -4,7 +4,12 @@ import { useNavigate, useParams } from "react-router-dom"; import { useLanguages } from "@hooks/useLanguages"; import { AppState, LanguageType, SnippetType } from "@types"; import { configureUserSelection } from "@utils/configureUserSelection"; -import { defaultLanguage, defaultState } from "@utils/consts"; +import { + defaultCategoryName, + defaultLanguage, + defaultSlugifiedSubLanguageName, + defaultState, +} from "@utils/consts"; import { slugify } from "@utils/slugify"; const AppContext = createContext(defaultState); @@ -46,8 +51,16 @@ export const AppProvider: FC<{ children: React.ReactNode }> = ({ * Set the default language if the language is not found in the URL. */ useEffect(() => { - if (languageName === undefined) { - navigate(`/${slugify(defaultLanguage.name)}`, { replace: true }); + const resolvedLanguage = languageName || defaultLanguage.name; + const resolvedSubLanguage = + subLanguageName || defaultSlugifiedSubLanguageName; + const resolvedCategory = categoryName || defaultCategoryName; + + if (!languageName || !subLanguageName || !categoryName) { + navigate( + `/${slugify(resolvedLanguage)}/${slugify(resolvedSubLanguage)}/${slugify(resolvedCategory)}`, + { replace: true } + ); } // eslint-disable-next-line react-hooks/exhaustive-deps }, []); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy