【发布时间】:2020-12-15 17:30:52
【问题描述】:
我正在使用 material-ui (https://material-ui.com/) 设计一个网站。我有带按钮的工具栏。像往常一样,当我单击其中一个按钮并为新的 html 页面呈现初始组件时,我想导航另一个 html 页面。例如,从“Main Page”(目前,它的 localhost:3000/)到“About”页面(localhost:3000/About)。
我尝试了类似的方法,
import { Link } from 'react-router-dom';
function ListItemLink(props) {
const { icon, primary, to } = props;
const CustomLink = props => <Link to={'/About'} {...props} />;
return (
<Button component={CustomLink} /> About
);
}
https://github.com/mui-org/material-ui/issues/10955 但它不起作用。我搜索了许多其他方法,但它们都没有做我想要的。在下图中,我在公共文件夹下有“关于”和“新闻”文件夹。它们每个都有自己的 index.html 文件。而且我在 src 文件夹下也有 'index.js'。
默认情况下,nmp 在 'public' 文件夹下启动 index.html 并为此 html 文件执行 index.js。 当我通过按钮单击路由其他文件夹时,我想制作这种场景。
有没有更好的方法来做到这一点?
谢谢。
【问题讨论】:
标签: javascript reactjs react-router material-ui react-router-dom