0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Astroの動的ルーティング、静的ルーティング

Posted at

Webアプリケーション(SSR)におけるルーティング

動的ルーティング

リクエストごとにサーバー側で動的にHTMLを作成して返却する

静的ルーティング

ユーザーからのリクエストに対して、サーバーは事前に用意された静的なHTMLファイルをそのまま返す

Astroにおけるルーティング

静的ルーティング

/pageディレクトリ配下で作成されたページは、自動でルーティングに登録される

静的ルーティングの例

src/pages/index.astro        -> mysite.com/
src/pages/about.astro        -> mysite.com/about
src/pages/about/index.astro  -> mysite.com/about
src/pages/about/me.astro     -> mysite.com/about/me
src/pages/posts/1.md         -> mysite.com/posts/1

動的ルーティング

Astroページファイルのファイル名に動的ルートパラメータを指定すると、ファイルにマッチするページを複数生成できます。たとえばsrc/pages/authors/[author].astroは、ブログの各著者に対してプロフィールページを生成します。

動的ルートパラメータを指定して、複数ページを作ることを「動的ルーティング」と言っている。(おそらく)

Astroが定義する「動的ルーティング」の中に、「静的(SSG)モード」というものが存在する。

静的(SSG)モード
すべてのルートをビルド時に決める必要があるため、動的ルートはgetStaticPaths()をエクスポートし、そこでparamsプロパティをもつオブジェクトの配列を返す必要があります。各オブジェクトは対応するルートを生成します。

Astroではこれを「動的ルーティング」と定義づけられるが、
SSG(サーバーサイドジェネレータ)式だと、ビルド時にHTMLが生成されるため、webアプリケーション的には、静的ルーティングともいえると思う。

ページネーション作成時の参考

getStaticPaths()

参考

Astro公式 動的ルーティング
SSG,SSRの違い

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?