我在到达路由器嵌套路由时遇到问题,我正在尝试导航到 / 并呈现 page2,但是当路由更改为 // 时,我被困在同一页面的“/”主页上
<Appjs>
import React from "react";
import "./App.css";
import Homepage from "./Components/Homepage";
import Details from "./Components/Details";
function App() {
return (
<div>
<Router>
<Homepage path="/">
<Details path="details" />
</Homepage>
</Router>
</div>
);
}
export default App;
import React, { Component, useEffect, useState } from "react";
import styled, { isStyledComponent } from "styled-components";
import NavLink from "./NavLink";
import { Link } from "@reach/router";
const Homepage = () => {
const [users, setUsers] = useState([]);
return (
<React.Fragment>
<div className={"container"}>
<Styleddiv>
<h2>Select an Account</h2>
<div style={{ padding: 0 }}>
{Object.values(users).map((item) => (
<Link to={`details/${item.name}`}>
<img src={item.profilepicture} alt="Girl in a jacket"></img>
<span>{item.name}</span>
</Link>
))}
</div>
</Styleddiv>
</div>
</React.Fragment>
);
};
export default Homepage;
在路由器内部构建路由时我是否遗漏了什么,请帮助我
因此,在主页中,如果我单击任何链接,路线将更改为 /details 但详细信息页面无法呈现
https://codesandbox.io/s/billowing-hill-j5gmy?file=/src/Homepage.js