-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: url에 lang param이 있을 경우 브라우저 lang보다 우선하여 표시
- Loading branch information
Showing
6 changed files
with
121 additions
and
37 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
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
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 { useEffect } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { Outlet, useLocation, useNavigate, useParams } from "react-router-dom"; | ||
|
||
import { resources } from "@utils/i18n"; | ||
|
||
function LangLayout() { | ||
const { i18n } = useTranslation(); | ||
const navigate = useNavigate(); | ||
const { pathname } = useLocation(); | ||
const { lang = LangCode.EN } = useParams(); | ||
|
||
useEffect(() => { | ||
if (lang in resources) { | ||
i18n.changeLanguage(lang); | ||
} else { | ||
navigate(pathname.replace(`/${lang}`, ""), { replace: true }); | ||
} | ||
}, [lang]); | ||
|
||
return <Outlet />; | ||
} | ||
|
||
export default LangLayout; |
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