Reactルーティングのインストールと使用、およびルーティングに関する具体的な知識

2192 ワード

ルーティングのインストール
yarn add react-router-dom
ルーティングに必要なコンポーネントのインポート
import { BrowserRouter as Router, Route, Link } from “react-router-dom”;
ルーティングコンポーネントの説明
Router総ルーティングlinkルーティングナビゲーションlinkto切替接続RouteルーティングRoute対応リンクRoutecomponent対応コンポーネント
ルーティングのパラメータ
指定リンク命令の定義
  1

ルーティングの定義


コンポーネントの定義-ルーティングパラメータの取得
  function Produce({match}){
      return (

:{match.params.id}

); }

サブルート
  • Navlink
  • にインポート
    import {BrowserRouter as Router,Route,Link,NavLink} from 'react-router-dom'
    
  • 01定義命令Link命令
  •   
    
  • 02主ルーティング
  • を定義する.
    
    

    03マスタールーティングの作成
    function Detail({location,match}){
      return (
        
    | |

    ); } ## 04 `
    function Arg(){
      return (

    Arg

    ); }
    function Com(){
      return (

    com

    ); }

    `リダイレクト
    デフォルトのサブルーティングを書く必要があります.リダイレクト01を使用してリダイレクトをインポートできます
    import {
     BrowserRouter as Router,
     Route,
     Link,
     Switch,
     NavLink,
     Redirect
    }
    

    コンポーネントのパラメータ
    function About({match,history,location}){
      console.log(match,history,location)
      return (

    about

    ); }

    matchマッチングの現在のルーティング
    isExact:true,//params:{}//現在のルーティングのパラメータpath:{}//ルーティング指定path url:{}//link指定リンクアドレスを正確に一致するかどうか
    history現在のルーティング情報
    go()履歴ジャンプgoBack()履歴戻りgoFoward()前進length履歴の長さpush()ジャンプ履歴ありreplace()ジャンプ履歴なしlocationアドレス情報-hash#後のパラメータ-pathname現在ルーティングのアドレス-search疑問符後のパラメータ注釈:補足コンテンツclassプログラミングjsルーティングジャンプhistory.push(’/login’);