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

这个服务端渲染 不包括接口部分的数据拼接到html再渲染吗? #1

Open
The-End-Hero opened this issue Jan 29, 2018 · 5 comments

Comments

@The-End-Hero
Copy link

No description provided.

@yangfan0095
Copy link
Owner

包括啊 , 前端默认使用Redux ,服务端也是通过Redux 获取到数据 返回到前台

@yangfan0095
Copy link
Owner

@The-End-Hero 看这个代码

/**
 * 渲染服务端路由
 */
module.exports.render = async(ctx,next) =>{
    const { store ,history} = getCreateStore(ctx);
    const branch = matchRoutes(router, ctx.req.url);
    const promises = branch.map(({route}) => {
        const fetch = route.component.fetch;
        return fetch instanceof Function ? fetch(store) : Promise.resolve(null)
    });
    await Promise.all(promises).catch((err)=>{
        console.log(err);
    }); 

    const html = ReactDOMServer.renderToString(
                <Provider store={store}>
                            <StaticRouter
                            location={ctx.url}
                            context={{}}>
                                <App/>
                            </StaticRouter>
                </Provider>
        )
        let initState=store.getState();
        const body =  layout(html,initState);
   ctx.body =body;
}

@hamsterBiscuit
Copy link

我这里也是一样,首页渲染还是spa,不是ssr

@snowkeda
Copy link

我这里也是一样,首页渲染还是spa,不是ssr
你可以把serviceWorker 设置成默认不缓存。 这样你首次进入就会从服务端渲染了。

@beileixinqing
Copy link

我这里也是一样,首页渲染还是spa,不是ssr
你可以把serviceWorker 设置成默认不缓存。 这样你首次进入就会从服务端渲染了。

请问如何把serviceWorker 设置成默认不缓存?

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

5 participants