运行router.getMatchedComponents()

时间:2019-08-21 09:16:17

标签: javascript vue.js server-side-rendering

我正忙于创建带有服务器端渲染的Vue应用。到目前为止,基本应用程序运行良好,路由也可以运行,但是我的控制台会打印出{ code: 404 }文件中的entry-server.js

//entry-server.js

import { createApp } from './main.js';

export default context => {
    // since there could potentially be asynchronous route hooks or components,
    // we will be returning a Promise so that the server can wait until
    // everything is ready before rendering.
    return new Promise((resolve, reject) => {
        const { app, router } = createApp();

        // set server-side router's location
        router.push(context.url);

        // wait until router has resolved possible async components and hooks
        router.onReady(() => {
            const matchedComponents = router.getMatchedComponents();
            // no matched routes, reject with 404
            if (!matchedComponents.length) {
                return reject({ code: 404 });
            }

            // the Promise should resolve to the app instance so it can be rendered
            resolve(app);
        }, reject);
    });
}

因此,我可以看到在进行router.getMatchedComponents()时会发生这种情况,但我不知道为什么吗?

0 个答案:

没有答案