looking through the sample code from the react-starter-kit, I'm puzzled by what the statement require.ensure([], (require) => resolve(require('./Admin').default), 'admin');
does. I don't see that require.ensure is defined anywhere so I'm assuming it's a webpack function.
Is that an authorization check to make sure that the user has an admin role? If so, where is the user info and role info being instanciated?
Is it instead only to make sure the admin component is instanciated? What is the .default
property and what is the string 'admin' being used for?
import React from 'react';
import Layout from '../../components/Layout';
const title = 'Admin Page';
const isAdmin = false;
export default {
path: '/admin',
async action() {
if (!isAdmin) {
return { redirect: '/login' };
}
const Admin = await new Promise((resolve) => {
require.ensure([], (require) => resolve(require('./Admin').default), 'admin');
});
return {
title,
chunk: 'admin',
component: <Layout><Admin title={title} /></Layout>,
};
},
};