We solved this with a jet router:
<Route key="secured_component" path="/secured" onEnter={handleEnterSecuredComponent} getComponent=({nextState, cb) => { require.ensure([], () => { cb(null, require('YourComponent').default); }); }} /> ... const handleEnterSecuredComponent = (nextState, replace) => { const {login: {success}} = store.getState(); if (!success) { replace('/login'); } };
So, your login page should be set to redux {login: {success: true}} if the user is authenticated. If the authenticated user is trying to access / secure, he will be redirected to / login.
require.ensure does not play any role of authentication. This is just an entry point for webpack to split a piece of js files for lazy loading.
source share