I'm using react-router 2.4.0
with React 15.2.1
and Webpack. I see that styles are being loaded via IndexRoute component (Main, in this example) although it's not being loaded.
Consider the following sources:
AppRouter.js
<Router history={history}>
<Route path='/' component={App}>
<IndexRoute component={Main} onEnter={requireLogin} />
<Route path='login' component={LoginPage} />
</Route>
</Router>
function requireLogin(nextState, replace) {
if (!getIsUserLoggedIn()) {
replace('/login');
}
}
Main.js
...
import '../styles/Main.scss';
...
webpack.config.js:
...
module: {
loaders: [
{
test: /\.scss$/,
loader: 'style!css!sass!postcss-loader'
}
]
},
postcss: [autoprefixer({ browsers: ['last 2 versions'] })]
When navigating to /
and the user is logged out, the router do redirect to /login
, but all styles that are loaded in Main.scss
are being appended to the DOM.
How can I prevent that from happen, and load only LoginPage
component styles?