【发布时间】:2020-07-14 15:58:35
【问题描述】:
我正在学习 GatsbyJS/React,并且对整个编码非常陌生。我正在使用一个入门 gatsbyjs/React 模板来帮助我学习。
我只是想在页面上添加一个额外的导航链接,该链接链接到外部网站,而不是内部页面。现在写网站,导航栏是无状态的功能组件? (我认为)我可以添加指向内部页面的链接没问题,但是因为它将网站 URL 放在链接之前,所以我最终将网站 URL 放在我添加的每个导航链接的前面。导航文件是一个 jsx 文件。 任何帮助将不胜感激,所以我可以学习。
我尝试实施 GATSBYLINK,但无法正确实施。
这是来自 jsx 文件的导航代码的一部分:
const ListLink = (props) => (
<li className="c-main-nav__elem" >
<Link
to={props.to}
className="c-main-nav__link"
activeClassName="c-main-nav__link--is-active"
exact={true}
onClick={props.closeMenu}
>
{props.children}
</Link>
</li>
);
class MainNav extends React.Component {
constructor(props) {
super(props);
this.toggleMenu = this.toggleMenu.bind(this);
this.closeMenu = this.closeMenu.bind(this);
this.state = {
links: [
{ to: '/', text: 'Home', icon: FaMapMarker },
{ to: '/toolbox/', text: 'Toolbox', icon: FaWrench },
{ to: '/playground/', text: 'Playground', icon: FaPaperPlaneO },
{ to: '/contact/', text: 'Contact', icon: FaEnvelopeO }
],
mainNavModifierClassName: '',
mobileDetailsNav: null
}
}
【问题讨论】: