よく使う文字列を定数にして使いまわしたい #73
Replies: 12 comments 13 replies
-
技術ブログを調べるよりオープンソースのディレクトリ参考にする方が早いかも オープンソースのReact / Next.js製Webアプリまとめ -Zenn ルートディレクトリにlib/constants.ts作って以下のように設定してる模様
https://github.com/vercel/virtual-event-starter-kit/blob/main/lib/constants.ts |
Beta Was this translation helpful? Give feedback.
-
App Routerの設定と組み合わせると良い感じになりそうですね! こちらも参考になるかもしれません: |
Beta Was this translation helpful? Give feedback.
-
この辺のApp Routerの特別なファイルとかも、後々設定してまとめたいですよね! |
Beta Was this translation helpful? Give feedback.
-
https://nextjs.org/docs/app/api-reference/functions/generate-metadata
個人ページを表示させるときに |
Beta Was this translation helpful? Give feedback.
-
App RouterのOGP設定方法まとめ [Next.js] -Zenn export const metadata = {
title: {
default: siteName,
template: `%s - ${siteName}`,
},
description,
openGraph: {
title: siteName,
description,
url,
siteName,
locale: 'ja_JP',
type: 'website',
},
twitter: {
card: 'summary_large_image',
title: siteName,
description,
site: '@サイト用アカウントのTwitterID',
creator: '@作者のTwitterID',
},
verification: {
google: 'サーチコンソールのやつ',
},
alternates: {
canonical: url,
},
}; ドキュメントも見たけど、上記の設定しておけば良さそう? |
Beta Was this translation helpful? Give feedback.
-
ただ定数として使い回すには、
これを使いまわしたいページ(現状ではpage.tsx)でimportして使ったり、layout.tsxでimportしてmetadataとして設定したり |
Beta Was this translation helpful? Give feedback.
-
以下のリポジトリも結構参考になるかもです! メモ:
|
Beta Was this translation helpful? Give feedback.
-
verificationってなんだろう…… https://data.herohoro.com/blog/metadata-ref
認証とかに使うのかな……? |
Beta Was this translation helpful? Give feedback.
-
cahtGPT: Next.jsでalternatesプロパティを設定すると、以下の効果があります: Canonical URLの指定: |
Beta Was this translation helpful? Give feedback.
-
APIで取得したデータをもとに、動的にメタ情報を設定する方法(Next.js App Router)
!? |
Beta Was this translation helpful? Give feedback.
-
ここらへんの設定沼っぽそうなので、必要最低限の設定だけしときます……! |
Beta Was this translation helpful? Give feedback.
-
ファビコンの設定は |
Beta Was this translation helpful? Give feedback.
-
よく使う文字列を定数にして使いまわしたいです。
具体的には、
などでしょうか。
今後OGPの設定もするとなったら、より必要になってくるかな、と。
ザッと調査したところ、constants.tsファイルを作成して記述するのが一般的っぽい?
ChatGPTにnext.config.jsで定義するのはどうか質問したら、できるけど一般的ではないと回答がありました。
もしみなさんがよろしければファイル作成して定数定義しようと思うのですが、何かご意見やアドバイス等あればお聞かせ願いたいです!
参考
【フロントエンド】Next.jsの全体設定
Next.jsのディレクトリ構成を考えてみた -Zenn
Beta Was this translation helpful? Give feedback.
All reactions