Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@vueuse/head 1.x versions Rendering problem #208

Open
imp-oh opened this issue Jun 13, 2023 · 0 comments
Open

@vueuse/head 1.x versions Rendering problem #208

imp-oh opened this issue Jun 13, 2023 · 0 comments

Comments

@imp-oh
Copy link

imp-oh commented Jun 13, 2023

solution
vite-ssr\vue\entry-server.js

    const { headTags = '', htmlAttrs = '', bodyAttrs = '', } = head ? await renderHeadToString(head) : {};
import { createApp } from 'vue';
import { renderToString } from '@vue/server-renderer';
import { createRouter, createMemoryHistory } from 'vue-router';
import { getFullPath, withoutSuffix } from '../utils/route';
import { addPagePropsGetterToRoutes } from './utils';
import { renderHeadToString } from '@vueuse/head';
import coreViteSSR from '../core/entry-server.js';
import { provideContext } from './components.js';
export { ClientOnly, useContext } from './components.js';
export const viteSSR = function viteSSR(App, { routes, base, routerOptions = {}, pageProps = { passToPage: true }, ...options }, hook) {
    if (pageProps && pageProps.passToPage) {
        addPagePropsGetterToRoutes(routes);
    }
    return coreViteSSR(options, async (context, { isRedirect, ...extra }) => {
        const app = createApp(App);
        const routeBase = base && withoutSuffix(base(context), '/');
        const router = createRouter({
            ...routerOptions,
            history: createMemoryHistory(routeBase),
            routes: routes,
        });
        router.beforeEach((to) => {
            to.meta.state = extra.initialState || null;
        });
        provideContext(app, context);
        const fullPath = getFullPath(context.url, routeBase);
        const { head } = (hook &&
            (await hook({
                app,
                router,
                initialRoute: router.resolve(fullPath),
                ...context,
            }))) ||
            {};
        app.use(router);
        router.push(fullPath);
        await router.isReady();
        if (isRedirect())
            return {};
        Object.assign(context.initialState || {}, (router.currentRoute.value.meta || {}).state || {});
        const body = await renderToString(app, context);
        if (isRedirect()) return {};
        const { headTags = '', htmlAttrs = '', bodyAttrs = '', } = head ? await renderHeadToString(head) : {};
        return { body, headTags, htmlAttrs, bodyAttrs };
    });
};
export default viteSSR;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant