第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在 React 中顯示默認(rèn)視圖?

如何在 React 中顯示默認(rèn)視圖?

紅顏莎娜 2023-08-05 19:25:26
Home我有一個(gè)具有三個(gè)不同路線的 React 站點(diǎn),當(dāng)用戶進(jìn)入該站點(diǎn)時(shí),我希望它自動(dòng)顯示第一個(gè)路線,稱為。這是我的代碼App.js:<Router>  <Navigation />  <Switch>    <Route path="/hypstats" exact component={() => <Home />} />    <Route path="/hypstats/auctions" exact component={() => <AuctionViewer />} />    <Route path="/hypstats/bazaar" exact component={() => <BazaarViewer />} />  </Switch></Router>這是Navigation組件:import React, { Component } from 'react';import { Link } from 'react-router-dom';import "../App.css"function Navigation(props) {    return (        <div className="navbar">            <Link className="navlink" to="/hypstats">HypStats</Link>             <Link className="navlink" to="/hypstats/auctions">Auctions</Link>            <Link className="navlink" to="/hypstats/bazaar">Bazaar</Link>        </div>    )}export default Navigation;
查看完整描述

3 回答

?
慕妹3242003

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超6個(gè)贊

要將任何視圖設(shè)為默認(rèn)視圖,您可以將以下內(nèi)容添加到導(dǎo)航中


<Route path="/" exact component={() => <Home />} />

或者你可以寫如下:


<Redirect from="/" to="/hypstats"}  />



<Router>

    <Navigation />

        <Switch>

            <Route path="/hypstats" exact component={() => <Home />} />

            <Route path="/hypstats/auctions" exact component={() => <AuctionViewer />} />

            <Route path="/hypstats/bazaar" exact component={() => <BazaarViewer />} />

            **<Route path="/" exact component={() => <Home />} />**

        </Switch>

</Router>


查看完整回答
反對(duì) 回復(fù) 2023-08-05
?
月關(guān)寶盒

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超5個(gè)贊

我們使用 basename 屬性來(lái)告訴站點(diǎn)的基本名稱。/hypstats這樣,在接下來(lái)的路由中,每次添加新路由時(shí),我們就不必在此處手動(dòng)設(shè)置基本名稱。React Router 自己管理它。


<Router basename="/hypstats">

  <Navigation />

  <Switch>

    <Route path="/" exact component={() => <Home />} />

    <Route path="/auctions" exact component={() => <AuctionViewer />} />

    <Route path="/bazaar" exact component={() => <BazaarViewer />} />

  </Switch>

</Router>


查看完整回答
反對(duì) 回復(fù) 2023-08-05
?
jeck貓

TA貢獻(xiàn)1909條經(jīng)驗(yàn) 獲得超7個(gè)贊

在您的應(yīng)用程序組件中的某個(gè)位置運(yùn)行它。

history.push({
     pathname: '/hypstats',
});

您正在使用“react-router-dom”,因此您可以導(dǎo)入:

import { useHistory } from "react-router-dom";

然后你可以使用:

const history = useHistory();

因此,每當(dāng)用戶進(jìn)入您的 React 應(yīng)用程序時(shí),它都會(huì)打開“/hypstats”。

您可以在 useEffect 中執(zhí)行此操作。


查看完整回答
反對(duì) 回復(fù) 2023-08-05
  • 3 回答
  • 0 關(guān)注
  • 165 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)