After lots of research i got the right answer for my case.
First of all my React application is a server rendered app.
Second; i am using React Router Switch because of performance related issues.
Above solution not worked for me because of my app architecture and i got some errors like;
You should not use Route component and Route children in the same route; Route children will be ignored
So here; i want to use React Router Switch with multiple layouts. And here is how to do it.
First you will create a custom Router component which combines the Layout and Component. Say "AppRouter"
const AppRouter = ({ component: Component, layout: Layout, ...rest }) => (
<Route {...rest} render={props => (
<Layout>
<Component {...props} />
</Layout>
)} />
)
Second; for public and private routes there must be two different layout wrapper
const LandingRouteLayout = props => (
<div>
<LandingLayout {...props}/>
</div>
)
const AppRouteLayout = props => (
<div>
<AppLayout {...props}/>
</div>
)
Last; Routes
const Routes = () => {
return (
<Switch>
<AppRoute exact path="/" layout={LandingRouteLayout} component={Home} />
<AppRoute path="/login" layout={LandingRouteLayout} component={Login} />
<AppRoute path="/signup" layout={LandingRouteLayout} component={Signup} />
<AppRoute path="/t/:token" layout={AppRouteLayout} component={SetToken} />
<AppRoute path='/dashboard' layout={AppRouteLayout} component={DashboardPage} />
<AppRoute path="/u/:username" layout={AppRouteLayout} component={AccountPage} />
<Route component={NotFound} />
</Switch>
)
}
exactof typestringsupplied toRoute, expectedboolean. in Route in Routes in Router in StaticRouter in Provider in LocaleProvider