Next.js NextJs-Apollo-第一次渲染不是SSR
我正在为SSR和graphQL(Apollo)使用NextJs(9.3.0) 我的应用程序运行良好,但当我检查谷歌看到的内容时,阿波罗的数据不可用 如果我在做Next.js NextJs-Apollo-第一次渲染不是SSR,next.js,apollo,server-side-rendering,Next.js,Apollo,Server Side Rendering,我正在为SSR和graphQL(Apollo)使用NextJs(9.3.0) 我的应用程序运行良好,但当我检查谷歌看到的内容时,阿波罗的数据不可用 如果我在做卷曲https://myWebsite.com随机地,我有的内容(比如谷歌)没有阿波罗的数据,有的内容有阿波罗的数据 出于SEO目的,我需要始终使用buy my Backend(Apollo)提供的数据进行第一次渲染(刷新后) 这是我的文件:apolloClient.tsx import { ApolloClient } from "ap
卷曲https://myWebsite.com
随机地,我有的内容(比如谷歌)没有阿波罗的数据,有的内容有阿波罗的数据
出于SEO目的,我需要始终使用buy my Backend(Apollo)提供的数据进行第一次渲染(刷新后)
这是我的文件:apolloClient.tsx
import { ApolloClient } from "apollo-client";
import { AUTH_TOKEN } from "./config";
import { InMemoryCache } from "apollo-cache-inmemory";
import { HttpLink } from "apollo-link-http";
import Cookies from "js-cookie";
import fetch from "isomorphic-unfetch";
import nextCookies from "next-cookies";
import { uriBackend } from "./config";
let token = null;
export default function createApolloClient(initialState, ctx) {
// The `ctx` (NextPageContext) will only be present on the server.
// use it to extract auth headers (ctx.req) or similar.
// on server
if (ctx && ctx.req && ctx.req.headers["cookie"]) {
token = nextCookies(ctx)[AUTH_TOKEN];
// on client
} else {
// console.log("with data get client cookie");
token = Cookies.get(AUTH_TOKEN);
}
const headers = token ? { Authorization: `Bearer ${token}` } : {};
return new ApolloClient({
ssrMode: Boolean(ctx),
link: new HttpLink({
uri: uriBackend, // Server URL (must be absolute)
fetch,
headers
}),
cache: new InMemoryCache().restore(initialState)
});
}
你的页面代码在哪里?你的页面代码在哪里?