Javascript <;链接>;未在儿童中传播
我的工作是一个仪表板项目,我需要你的帮助。 我的应用程序中使用了React、nextjs和materialui。 在这个网站上,一个菜单被定义为可点击链接,用于在页面之间导航 但是,我无法从Javascript <;链接>;未在儿童中传播,javascript,reactjs,next.js,Javascript,Reactjs,Next.js,我的工作是一个仪表板项目,我需要你的帮助。 我的应用程序中使用了React、nextjs和materialui。 在这个网站上,一个菜单被定义为可点击链接,用于在页面之间导航 但是,我无法从下一个/link正确使用 在我的应用程序中,我需要将与以下内容结合使用: import Foo from './foo'; [...] <Link href="/about" passHref> <Foo /> </Link> [...] function MenuI
下一个/link
正确使用
在我的应用程序中,我需要将
与以下内容结合使用:
import Foo from './foo';
[...]
<Link href="/about" passHref>
<Foo />
</Link>
[...]
function MenuItem() {
return (
<> // here
<a>not ok - link is not clickable even if the following lines are commented</a>
<br />
<Link href="/about" passHref>
<a>ok - link is clickable</a>
</Link>
<Link href="/about" passHref>
<a>ok - link is clickable</a>
</Link>
<Link href="/about" passHref>
<div className="useless">
foo
<a>even with something more complicated</a>
<br />
<a>the 2 links are clikable</a>
bar
</div>
</Link>
</> // and here
);
}
从“/Foo”导入Foo;
[...]
[...]
在另一个文件中定义并包含
如果gist已关闭或将来已删除,则代码如下:
pages/index.jsx:
从“React”导入React;
从“./组件/菜单”导入菜单;
函数Home(){
返回;
}
导出默认主页;
components/Menu.jsx:
从“React”导入React;
从“下一个/链接”导入链接;
从“/MenuItem”导入MenuItem;
功能菜单(){
返回(
);
}
导出默认菜单;
组件/MenuItem.jsx:
从“React”导入React;
从“下一个/链接”导入链接;
函数MenuItem(){
返回(
这两个链接是可点击的
酒吧
);
}
导出默认菜单项;
如果我将
放在同一个文件中的
之间,则一切正常,并按需要工作,但如果我在组件上应用
,则情况并非如此。
如您所见,即使我设置了passHref
如何使我的
在菜单.jsx
中工作
注意。尝试用片段替换周围的div
,如下所示:
import Foo from './foo';
[...]
<Link href="/about" passHref>
<Foo />
</Link>
[...]
function MenuItem() {
return (
<> // here
<a>not ok - link is not clickable even if the following lines are commented</a>
<br />
<Link href="/about" passHref>
<a>ok - link is clickable</a>
</Link>
<Link href="/about" passHref>
<a>ok - link is clickable</a>
</Link>
<Link href="/about" passHref>
<div className="useless">
foo
<a>even with something more complicated</a>
<br />
<a>the 2 links are clikable</a>
bar
</div>
</Link>
</> // and here
);
}
函数MenuItem(){
返回(
//这里
这两个链接是可点击的
酒吧
//这里呢
);
}
function MenuItem() {
return (
<> // here
<a>not ok - link is not clickable even if the following lines are commented</a>
<br />
<Link href="/about" passHref>
<a>ok - link is clickable</a>
</Link>
<Link href="/about" passHref>
<a>ok - link is clickable</a>
</Link>
<Link href="/about" passHref>
<div className="useless">
foo
<a>even with something more complicated</a>
<br />
<a>the 2 links are clikable</a>
bar
</div>
</Link>
</> // and here
);
}