function handleMiddlewares() {
    router.beforeEach(async (to, from, next) => {
        // Avoid loop redirect with next(path)
        const fromPath = from.fullPath.split('#')[0];
        const toPath = to.fullPath.split('#')[0];
        if (fromPath === toPath) {
            return next();
        }

        let matchedComponents = router.getMatchedComponents(to);

        // all + client + components middlewares
        let middlewareNames = [
            ...(middConf.all || []),
            ...(middConf.client || []),
            ...matchedComponents
                .filter(({middleware}) => !!middleware)
                .reduce((arr, {middleware}) => arr.concat(middleware), [])
        ];

        // get all the middlewares defined by user
        const middlewares = await getMiddlewares(middlewareNames);

        let unknowMiddleware = middlewareNames.find(name => typeof middlewares[name] !== 'function');
        if (unknowMiddleware) {
            throw new Error(`Unknown middleware ${unknowMiddleware}`);
        }

        let nextCalled = false;
        const nextRedirect = opts => {
            if (loading.finish) {
                loading.finish();
            }
            if (nextCalled) {
                return;
            }
            nextCalled = true;

            if (opts.external) {
                opts.query = stringify(opts.query);
                opts.path = opts.path + (opts.query ? '?' + opts.query : '');

                window.location.replace(opts.path);
                return next();
            }
            next(opts);
        };

        // create a new context for middleware, contains store, route etc.
        let contextInMiddleware = getClientContext({
            to,
            from,
            store,
            next: nextRedirect
        }, app);

        let matchedMiddlewares = middlewareNames.map(name => middlewares[name]);
        await execSeries(matchedMiddlewares, contextInMiddleware);

        if (!nextCalled) {
            next();
        }
    });
}
Use async CSS in SPA under following
1. `skeleton.enable`
2. `skeleton.asyncCSS`
3. `build.cssExtract`