我正在渲染一个react-bootstrap导航栏,但是我得到的是混乱的文本,没有任何引导样式。
我有引导CDN标签。我已经用npm将react-bootstrap安装到了项目中。我还确保不要使用Bootstrap 4标记,因为如家所说,它与react-bootstrap不兼容,我按照https://react-bootstrap.github.io/getting-started/introduction/的指示将以下几行添加到index.html中。
<script src="https://unpkg.com/react/umd/react.production.js" crossorigin />
<script
src="https://unpkg.com/react-dom/umd/react-dom.production.js"
crossorigin
/>
<script
src="https://unpkg.com/react-bootstrap@next/dist/react-bootstrap.min.js"
crossorigin
/>
<script>var Alert = ReactBootstrap.Alert;</script>
我也尝试了所有可以找到的针对此问题的已发布解决方案。我不确定我在做什么错...
Index.html(显然只有脚本标记)
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://unpkg.com/react/umd/react.production.js" crossorigin />
<script
src="https://unpkg.com/react-dom/umd/react-dom.production.js"
crossorigin
></script>
<script
src="https://unpkg.com/react-bootstrap@next/dist/react-bootstrap.min.js"
crossorigin
></script>
<script>var Alert = ReactBootstrap.Alert;</script>
Index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
ReactDOM.render(<App />, document.getElementById('root'));
serviceWorker.unregister();
App.js
import React from 'react';
import Navbar from 'react-bootstrap/Navbar'
import Nav from 'react-bootstrap/Nav'
import NavDropdown from 'react-bootstrap/NavDropdown'
import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
<Navbar collapseOnSelect expand="lg" bg="dark" variant="dark">
<Navbar.Brand href="#home">React-Bootstrap</Navbar.Brand>
<Navbar.Toggle aria-controls="responsive-navbar-nav" />
<Navbar.Collapse id="responsive-navbar-nav">
<Nav className="mr-auto">
<Nav.Link href="#features">Features</Nav.Link>
<Nav.Link href="#pricing">Pricing</Nav.Link>
<NavDropdown title="Dropdown" id="collasible-nav-dropdown">
<NavDropdown.Item href="#action/3.1">Action</NavDropdown.Item>
<NavDropdown.Item href="#action/3.2">Another action</NavDropdown.Item>
<NavDropdown.Item href="#action/3.3">Something</NavDropdown.Item>
<NavDropdown.Divider />
<NavDropdown.Item href="#action/3.4">Separated link</NavDropdown.Item>
</NavDropdown>
</Nav>
<Nav>
<Nav.Link href="#deets">More deets</Nav.Link>
<Nav.Link eventKey={2} href="#memes">
Dank memes
</Nav.Link>
</Nav>
</Navbar.Collapse>
</Navbar>;
</div>
);
}
export default App;
答案 0 :(得分:1)