索引.jsximport React from "react";import ReactDOM from "react-dom";import { Route, Router, Switch } from "react-router-dom";import App from "./components/App.jsx";import SearchResults from "./components/SearchResults.jsx";import history from "./history.js";import SearchProvider from "./context/SearchContext.jsx";const routing = ( <Router history={history}> <div> <Switch> <SearchProvider> <Route path="/search" component={SearchResults} /> <Route exact path="/" component={App} /> </SearchProvider> </Switch> </div> </Router>);ReactDOM.render(routing, document.getElementById("app"));應(yīng)用程序.jsximport React, { useState } from "react";import styles from "../modules/app.module.css";import Search from "./Search.jsx";import { Link } from "react-router-dom";const App = (props) => { return ( <div className={styles.appContainer}> <div className={styles.title}>BGrules</div> <Search /> <Link to="/search"> <button>Click me</button> </Link> </div> );};export default App;搜索結(jié)果.jsximport React from "react";import styles from "../modules/searchResults.module.css";const SearchResults = (props) => { return ( <div className={styles.resultContainer}> <div className={styles.title}>Search Results</div> <div className={styles.subTitle}>results for term:</div> </div> );};export default SearchResults;我遇到的問(wèn)題是,當(dāng)我在 url 中鍵入路由 /search 時(shí),它會(huì)毫無(wú)問(wèn)題地將我?guī)У秸_的頁(yè)面,但是當(dāng)我嘗試在我的 App 文件中使用 Link 或 Redirect 時(shí),它會(huì)更改 url 但不會(huì)加載該組件(只是一個(gè)空白的白頁(yè))我在控制臺(tái)中沒(méi)有收到任何錯(cuò)誤。我不熟悉在這里提問(wèn),所以希望我以一種有意義的方式提問(wèn)。提前致謝!
我在使用重定向和鏈接更改我的 React 路由時(shí)遇到困難
交互式愛(ài)情
2023-01-06 11:17:21