5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Next.jsの動的ページ遷移を高速化する為のサンプル

Posted at

#Linkコンポーネントを使う

遅いサンプル

        <button
          onClick={() => router.push(`/sample/${id}/edit`)}
        >
          Edit
        </button>

速いサンプル

        <Link href="/sample/[id]/edit" as={`/sample/${id}/edit`}>
          <button className="btn btn-warning btn-lg" href="#" role="button">
            Edit
          </button>
        </Link>

#Router.pushで第二引数まで書く

遅いサンプル

    updateSample(sample).then(updatedSample => {
      Router.push(`/sample/${sample.id}`);
    });

速いサンプル

    updateSample(sample).then(updatedSample => {
      Router.push("/sample/[id]", `/sample/${sample.id}`);
    });
5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?