I am trying to build multipurpose website to React using react-router v5 for routing. For normal routing we have routes like
localhost:3000/posts localhost:3000/gallery
But for some other case I want to have subdomain lets say blog.
blog.localhost:3000 // render blog component
or
subdomain.localhost:3000 // render some component.
For now this also renders the same component as localhost:3000.
So, is there any way I can do this in react?
Current routes look like this.
function App() {
return (
<React.Fragment>
<React.Suspense fallback={<></>}>
<Router history={history}>
<Switch>
<Redirect exact from="/" to="/home" />
<Route exact path="/login" component={LoginPage} />
<ProtectedRoute exact={true} path="/profile" component={ProfilePage} />
<ProtectedRoute exact={true} path="/home" component={HomePage} />
<ProtectedRoute exact={true} path="/gallery/:subdomain" component={Gallery} />
<Route exact path="/gallery/post/:subdomain/:postid" component={SinglePostView} />
<Route component={PageNotFound} />
</Switch>
</Router>
</React.Suspense>
</React.Fragment>
);
}