【问题标题】:Is it the best way to call the api for seo with Next?这是用 Next 调用 api 进行 seo 的最佳方式吗?
【发布时间】:2021-08-28 22:23:58
【问题描述】:

我正在使用 swr 从 api 获取数据。我怀疑它是否实际上是在服务器端完成的。我想有好的 seo 并在加载页面之前加载。我见过 getServerSideProps () 但我有疑问,因为我是新手,接下来要做出反应

import React from "react";
import useSWR from "swr";

const fetcher = (url) => fetch(url).then((res) => res.json());

export default function App() {
    const { data, error } = useSWR(
        "my_url_api",
        fetcher
    );
    console.log(data);

    if (error) return "An error has occurred.";
    if (!data) return "Loading...";
    return (
        <div>
            <div>
                <h1>Esta es la web</h1>
            </div>
            {
                data.videos.map(({ item, title, embed, rate, default_thumb: { src } }) =>

                    <>
                        <h3>{title}</h3>
                        <img src={src} alt="Picture of the author" />
                        <iframe width="1225" height="625" src={embed}></iframe>
                        <p>{rate}</p>

                    </>
                )
            }
        </div>
    );
}

【问题讨论】:

标签: api next.js


【解决方案1】:

这取决于您的用例和您要获取的数据类型。 swr 用于客户端渲染。

查看此doc 以确定您的用例

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-12
    • 2019-11-08
    • 1970-01-01
    相关资源
    最近更新 更多