I wrote the react route code as below, everything works fine.
export const RoutePage = () => {
return <BrowserRouter>
<Routes>
<Route element={<DefaultLayout/>}>
<Route path='/' element={<Main />} />
<Route path='/login' element={<LoginPage />} />
<Route path='/register' element={<RegisterPage />} />
<Route path='/mypage' element={<MyPage />} />
<Route path='*' element={<NotFoundPage />}/>
</Route>
</Routes>
</BrowserRouter>
}
However, there is a situation where a subdomain is required, how to set up a subdomain in this case?
In the current state, if you connect to localhost:3000/myinfo, you will be connected to the page, but,
If I connect to admin.localhost:3000/myinfo, I should be connected to another page. What should I do in this case?
2
Answers
I figured out how to control the right page for each domain, I received good answers in the current post, but the method below was the best in my situation.
I searched for the current connection url on the start page and connected the router suitable for the subdomain.
I don't have much experience, but this answer gave me what I wanted without creating another project, if you have any other ideas please let me know thanks!
Are you comfortable with DNS type A records?
If so, you can create a subdomain and point it to the same IP address as your react application.
For example:
your react application runs on this IP address: 127.0.0.1
your-domain.com points to this IP address: 127.0.0.1
subdomain.your-domain.com also points to this address: 127.0.0.1
This way, I think your-domain.com/myinfo and subdomain.your-domain.com/myinfo will refer to the same route on your application.