如何使用 Reactstrap 扩展导航栏
我是 Reactstrap 的新手。我的导航栏切换器不起作用,我的导航栏正在扩展,我不知道为什么。我认为我理解它背后的逻辑,但我无法让它正常工作
//imports
import { * } from "reactstrap";
import React from "react";
import "bootstrap/dist/css/bootstrap.css";
// 代码
<Navbar color="light" fixed="top" light>
<NavbarBrand href="/">reactstrap</NavbarBrand>
<NavbarToggler onClick={function noRefCheck() {}} />
<Collapse navbar>
<Nav className="me-auto" navbar>
<NavItem>
<NavLink href="/components/">Components</NavLink>
</NavItem>
<NavItem>
<NavLink href="https://github.com/reactstrap/reactstrap">
GitHub
</NavLink>
</NavItem>
<UncontrolledDropdown inNavbar nav>
<DropdownToggle caret nav>
Options
</DropdownToggle>
<DropdownMenu right>
<DropdownItem>Option 1</DropdownItem>
<DropdownItem>Option 2</DropdownItem>
<DropdownItem divider />
<DropdownItem>Reset</DropdownItem>
</DropdownMenu>
</UncontrolledDropdown>
</Nav>
<NavbarText>Simple Text</NavbarText>
</Collapse>
</Navbar>
i am new to working with Reactstrap. My Navbar Toggler isn't working and my Navbar isn' expanding and I don' know why. I think that i understood the logic behind it but i can't get it to work properly
//imports
import { * } from "reactstrap";
import React from "react";
import "bootstrap/dist/css/bootstrap.css";
// Code
<Navbar color="light" fixed="top" light>
<NavbarBrand href="/">reactstrap</NavbarBrand>
<NavbarToggler onClick={function noRefCheck() {}} />
<Collapse navbar>
<Nav className="me-auto" navbar>
<NavItem>
<NavLink href="/components/">Components</NavLink>
</NavItem>
<NavItem>
<NavLink href="https://github.com/reactstrap/reactstrap">
GitHub
</NavLink>
</NavItem>
<UncontrolledDropdown inNavbar nav>
<DropdownToggle caret nav>
Options
</DropdownToggle>
<DropdownMenu right>
<DropdownItem>Option 1</DropdownItem>
<DropdownItem>Option 2</DropdownItem>
<DropdownItem divider />
<DropdownItem>Reset</DropdownItem>
</DropdownMenu>
</UncontrolledDropdown>
</Nav>
<NavbarText>Simple Text</NavbarText>
</Collapse>
</Navbar>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您使用的是
Collapse
组件,因此它需要一个名为isOpen
的 prop,并且需要在单击时更新传递给
。isOpen
的值>导航栏切换器//代码
在导航栏标记中使用
expand={"lg"}
,这样如果屏幕较大,它将完全展开,而对于较小的屏幕,它将折叠。As you are using
Collapse
componet so, it need a prop calledisOpen
and need to update the value passed toisOpen
when clicking on theNavbarToggler
.//Code
Use
expand={"lg"}
in Navbar tag so that if its bigger screen then it will expand fully and for smaller screen it be collapse.您不能使用 {*} 来调用 Reactstrap 组件。您需要调用代码中使用的每个组件。
这可能会帮助您解决
需要使用
expand={true}
或使用扩展中的任何人 sm,md, lg,xl, true, false 这些都是您可以调用的按要求出来。对于
DropdownMenu
,right
属性已被弃用,请改用end
。欲了解更多详细信息,您可以访问reactstrap的文档页面。
You cant use {*} for calling the reactstrap components. You need to call each components that you use in code.
This might help you out
you need to use
expand={true}
or use anyone in expand sm,md, lg,xl, true, false these are all you can call out as per requirement.For
DropdownMenu
theright
property has been Deprecated useend
instead.For more details you can visit the document page of reactstrap.