let me explain clearly what I want to do?
row | current url | redirect to | component
1 | localhost:3000/panel | localhost:3000/en/panel | <Panel />
2 | localhost:3000/login | localhost:3000/en/panel | <Panel />
3 | localhost:3000/anyLang/panel | localhost:3000/sameLang/panel | <Panel />
4 | localhost:3000/anyLang/login | localhost:3000/sameLang/panel | <Panel />
5 | localhost:3000/ | holding.localhost:3000/en | <HoldingPage />
6 | localhost:3000/anyLang | holding.localhost:3000/sameLang | <HoldingPage />
7 | anySubDomain.localhost:3000/ | sameSubDomain.localhost:3000/en | <BlogPage />
8 | anySubDomain.localhost:3000/anyLang | sameSubDomain.localhost:3000/sameLang| <BlogPage />
I know part of the solution, although I’m not sure if it’s the best solution, please help me complete and optimize the solution.
For the first 4 items, they will all call the panel component, I use this solution
var
url = window.location.href,
subdomin = window.location.host.split(".")[0],
pathName = useLocation().pathname;
if( pathName.match(/((fa)|(en)|(ar)/)?((login)|(panel))/) ){
return(
<Routes>
<Route path="login" element={<Navigate replace to="/en/login" />} />
<Route path="panel" element={<Navigate replace to="/en/panel" />} />
<Route path="/:lang">
<Route path="login" element={<Panel />} />
<Route path="panel" element={<Panel />} />
</Route>
</Routes>
)
}
But for the next 4 modes, I don’t know what to do?
2
Answers
I found the solution, but still the challenge to find better answers.
and this is a shorest answer