我对ReactJS的世界还有点陌生,但我已经用Javascript编写代码有一段时间了。我喜欢ReactJS正在做的事情,因为我在使用设计模式和OOP之前是用纯JS编码的,我认为这对我来说是一个巨大的升级。
不久前,我开始使用react-starter-kit from kriasoft。此外,我将react-bootstrap集成到这个项目中,以使我的生活变得更容易。我按照react-bootstrap中的教程操作,并成功地添加了Bootstrap。
问题是,我现在不能使用react-starter-kit中的<Link />构建,因为它的简单性和“强大”,我很喜欢它。
react-bootstrap的官方方法是安装react-router-bootstrap并将<Link to="/path">替换为<LinkContainer to="/path">,但这意味着我必须将react-routing和universal-routing替换为react-router,这是我希望避免的事情。
集成react-bootstrap和react-starter-kit并仍然能够使用通用路由的正确方法是什么?为了使LinkContainer的行为像Link组件一样,我应该进行哪些更改?
当使用来自react-starter-kit的链接组件时,出现这种错误警告: validateDOMNesting(...):不能作为的后代出现。有关此问题,请参阅Header > NavItem > SafeAnchor >a> ... >链接> a.相关链接。(React-Bootstrap link item in a navitem)
来自react-bootstrap和react-router的官方推荐。(https://github.com/ReactTraining/react-router/issues/83#issuecomment-214794477)
同样,正如我所说的,我对reactJS还有点陌生,有可能我错过了一些东西。如果有人能澄清Link component from react-starter-kit和Link from react-router之间的区别,那就太好了。提前感谢
发布于 2016-11-24 18:18:57
我开始使用我自己的NavItem组件,而不是原来的:
import React, { PropTypes } from 'react';
import cx from 'classnames';
import Link from '../Link';
class NavItem extends React.Component {
static propTypes = {
className: PropTypes.string,
href: PropTypes.string.isRequired,
active: PropTypes.bool,
disabled: PropTypes.bool,
children: PropTypes.node.isRequired,
onClick: PropTypes.func,
};
static defaultProps = {
active: false,
disabled: false,
};
render() {
const { className, href, active, disabled, children, onClick } = this.props;
return (
<li role="presentation" className={cx(className, { active, disabled })}>
<Link to={href} onClick={onClick}>
{children}
</Link>
</li>
);
}
}
export default NavItem;这是我现在所遵循的方法,这要归功于this post。
https://stackoverflow.com/questions/40750569
复制相似问题