-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
react-bootstrap compatibility #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hey @flosse, its not currently not possible to override the
|
hmm...and how can I access the current active link? I need to set the |
related #85 |
ok, here is my current hacky workaround: module.exports = React.createClass
isActive: (name) -> window.location.hash.indexOf('#/' + name) isnt -1
onSelect: (id) -> Router.transitionTo.bind null, id
render: ->
Navbar null,
Nav null,
for l, key in links
props = { key, onSelect: @onSelect(l.id), active: @isActive(l.id) }
NavItem props, l.title Like mentioned in #85 it would be nice to extend the API to avoid such hacks. |
I think react-bootstrap should support specifying a custom link class. Would you mind opening an issue there? As a horrible hack, would something like this work temporarily?
Shudder. |
uuhh.... |
yeah, it's totally deranged - I'm certainly not recommending it. But |
8562482 adds an |
For the next person who googles this, I believe the current way to do this in react-router is to use
Thus the code could look like
|
From import { Link } from 'react-router';
// ...
<Nav>
<NavItem componentClass={Link} href="/economies" to="/economies">Economies</NavItem>
<NavItem componentClass={Link} href="/industries" to="/industries">Industries</NavItem>
</Nav> |
Making this big so it's easier to see. The official recommendation of the maintainers of React Router and React-Bootstrap is: Use React-Router-Bootstrap |
That |
Isn't it easier to just do import React, { PropTypes } from 'react';
import { Link, IndexLink } from 'react-router';
import SafeAnchor from 'react-bootstrap/lib/SafeAnchor';
function NavLink(props, context) {
const { tagName, children, componentClass, href, to, active, index } = props;
const newProps = {
componentClass: componentClass || (index ? IndexLink : Link),
to,
href: href || to,
active: active || context.router.isActive(to),
};
const Component = tagName || SafeAnchor;
return (
<Component {...newProps}>{children}</Component>
);
}
NavLink.contextTypes = {
router: PropTypes.object,
};
NavLink.propTypes = {
tagName: PropTypes.any,
children: PropTypes.node,
componentClass: PropTypes.any,
href: PropTypes.any,
to: PropTypes.any,
active: PropTypes.bool,
index: PropTypes.bool,
};
export default NavLink; |
Cloning elements is the standard API here, and is just about free outside of dev mode. RRB previously had a per-element wrappers, but the API just got unwieldy. A single container "just works". |
Wrap it like this, I made huge mistake here:
|
I did it the same way as @fengerzh and I'm getting an ' React.createElement: type should not be null, undefined, boolean, or number. ' error. What am I doing wrong? import { Navbar, Nav, NavItem } from 'react-bootstrap';
import LinkContainer from 'react-router-bootstrap';
<Nav>
<LinkContainer to='/view'>
<NavItem>test</NavItem>
</LinkContainer>
<NavItem eventKey={2} href="#">Link</NavItem>
</Nav> |
Sorry for late reply, I did not check my email frequently. Actually, the whole code is as below:
|
As recommended in upvoted comments, I tried to use the
It's crashing at this line of
My code is pretty simple though:
The package versions Im using:
Any ideas guys? @taion @fengerzh ? |
I'd like to combine react-bootstrap with
react-nested-router
.e.g. defining a navbar looks like this:
The problem here is that
NavItem
renders to an<li>
element with an<a>
tag. Do you have an Idea how I can tell theNavItem
that it should use theLink
class ofreact-nested-router
?The text was updated successfully, but these errors were encountered: