不加载Navbar组件,react-bootstrap

时间:2019-01-28 19:38:52

标签: javascript reactjs

我从React.js开始,制作导航菜单时发现了这个问题。它不会生成预期的菜单效果,这是代码:

import React, {Component} from 'react';
import {Link} from 'react-router-dom';
import { Navbar, Nav, NavItem} from 'react-bootstrap';
export class Menu extends Component {

    render(){
        return (
            
            <Navbar>
                <Nav>
                    <NavItem componentClass= {Link} href="/" to="/" >
                        Inicio
                    </NavItem>
                    <NavItem componentClass= {Link} href="/Pelicula" to="/Pelicula" >
                        Pelicula
                    </NavItem>
                </Nav>
            </Navbar>
         
        );
    }
}

export default Menu;

这是结果

enter image description here

它分为两个部分,顶部是“菜单”部分,底部是“问候”,但是我感兴趣的一项是菜单

希望您能帮忙

1 个答案:

答案 0 :(得分:-1)

  1. 确保您包含样式表
  

由于React-Bootstrap不依赖于Bootstrap的非常精确的版本,因此我们不附带任何附带的CSS。但是,使用这些组件需要一些样式表。哪种方式以及哪种引导方式取决于您自己,但是最简单的方法是包括CDN中的最新样式。

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

React-bootstrap - Getting Started


  1. NavItem中包裹BrowserRouter

import React from 'react';
import React, { Component } from 'react';
import { Link, BrowserRouter } from 'react-router-dom';
import { Navbar, Nav, NavItem } from 'react-bootstrap';

export class Menu extends Component {
  render() {
    return (
      <Navbar>
        <Nav>
          <BrowserRouter>
            <NavItem componentClass={Link} href="/" to="/">Inicio</NavItem>
          </BrowserRouter>
          <BrowserRouter>
            <NavItem componentClass={Link} href="/Pelicula" to="/Pelicula">Pelicula</NavItem>
          </BrowserRouter>
        </Nav>
      </Navbar>
    );
  }
}

export default Menu;

Stackblitz