我正在尝试编写带有身份验证的React应用。因此,导航栏上的某些字段只会显示给经过身份验证的用户。为此,我有一个Navbar.jsx文件和一个SignedInLinks.jsx文件。
我的NavBar.jsx:
import React from "react";
import { Link } from "react-router-dom";
import Signedinlinks from "./SignedInLinks";
const Navbar = () => {
return (
<nav className="navbar navbar-default navbar-dark bg-dark">
<div className="container">
<Link to="/" className="navbar-brand">
RS
</Link>
<Signedinlinks />
</div>
</nav>
);
};
export default Navbar;
我的SignedInLinks.jsx:
import React from "react";
import { NavLink } from "react-router-dom";
const Signedinlinks = () => {
return (
<ul className="navbar-nav">
<li className="nav-item">
<NavLink to="/">Edit Blogs</NavLink>
</li>
<li className="nav-item">
<NavLink to="/">Edit Photographs</NavLink>
</li>
<li className="nav-item">
<NavLink to="/" className="btn btn-primary">
RS
</NavLink>
</li>
</ul>
);
};
export default Signedinlinks;
我在index.html中将以下内容用于CSS:
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous"
/>
index.css具有:
body {
margin: 0;
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
monospace;
}
答案 0 :(得分:1)
因为导航栏不包含navbar-expand*
类之一。 Read the docs ...
“导航栏需要带有。 .navbar-expand {-sm | -md | -lg | -xl}用于响应折叠和颜色 方案类。”
此外,Bootstrap 4中没有navbar-default
。
答案 1 :(得分:0)
这是为了响应能力。你可以覆盖“flex-direction: row;”您的 "" 组件中的样式将解决该问题。
答案 2 :(得分:0)
只需将样式表 <link>
添加到您的 <head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">