【发布时间】:2023-01-16 22:41:32
【问题描述】:
我想有一个不同的导航栏对于我网站上的每条路径,我都想出了一个办法,但它并没有真正改变直到我刷新页面这显然不是我想要的。 (我正在使用反应路由器 v6。3个)
function Navbar() {
if (window.location.pathname === "/") {
return (
<nav style={{ backgroundColor: "rgb(17, 105, 142)" }}>...</nav>
);
} else if (window.location.pathname === "/products") {
return (
<nav className="products-nav">...</nav>
);
} else if (window.location.pathname === "/addproducts") {
return (
<nav className="addproducts-nav">...</nav>
);
} else ...
Here的完整代码以防万一
【问题讨论】:
标签: reactjs react-router react-router-dom