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?

Reactを使ってブログサイトを作る 06 - 二次ルートの設定

Last updated at Posted at 2024-12-30

二次ルートの設定

  • pages ディレクトリ内に、次のページ用のフォルダをそれぞれ作成します:Home(データ概要)/Article(コンテンツ管理)/Publish(記事公開)。各フォルダ内に index.jsx を作成し、基本的なコンポーネントを作成後、エクスポートします。

image.png

  • router/index.js にて、ネストされたサブルートを設定し、Layout 内にサブルートの出口を設定します。

image.png

  • Link を使用して、左側メニューの内容を変更し、サブルート規則と一致させてルーティングの切り替えを実現します。

image.png

  • 効果

image.png
image.png
image.png

URLに基づいてメニューをハイライト

実装効果

  • ページをリフレッシュした際、現在のルートパスに基づいて左側メニューが対応する項目をハイライト表示する。
    image.png

思考の分析

    1. 現在のulのルートパスを取得する。
    1. メニューコンポーネントでハイライトを担当する属性を見つけ、現在のルートパスをバインドする。
      image.png
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?