zoukankan      html  css  js  c++  java
  • Route

    Route

      The Route component is perhaps the most important component in React Router to understand and learn to use well. Its most basic responsibility is to render some UI when a location matches the route’s path.

    1、Route的基本用法

    import { BrowserRouter as Router, Route } from 'react-router-dom'
    
    <Router>
      <div>
        <Route exact path="/" component={Home}/>
        <Route path="/news" component={NewsFeed}/>
      </div>
    </Router>

      If the location of the app is / then the UI hierarchy will be something like:

    <div>
      <Home/>
      <!-- react-empty: 2 -->
    </div>

      And if the location of the app is /news then the UI hierarchy will be:

    <div>
      <!-- react-empty: 1 -->
      <NewsFeed/>
    </div>

    The “react-empty” comments are just implementation details of React’s null rendering. But for our purposes, it is instructive. A Route is always technically “rendered” even though its rendering null. As soon as the app location matches the route’s path, your component will be rendered.

     2、Route render methods

      

      Each is useful in different circumstances. You should use only one of these props on a given <Route>. See their explanations below to understand why you have 3 options. Most of the time you’ll use component.

    3、Route props

      

    4、exact: bool

      When true, will only match if the path matches the location.pathname exactly.

      

    参考:https://reacttraining.com/react-router/web/api/Route

  • 相关阅读:
    WML
    CocoaPods install 安装
    刷新控件,审核
    UIImageView
    课堂练习——返回一个一维整数数组中最大子数组的和
    团队与题目介绍
    学习进度条05
    软件工程结对作业02
    课堂练习——返回一个整数数组中最大子数组的和
    学习进度条04
  • 原文地址:https://www.cnblogs.com/tekkaman/p/6991821.html
Copyright © 2011-2022 走看看