我使用: ” @ material-ui / core“:” ^ 4.1.1“, “ react”:“ ^ 16.8.6”, “ react-dom”:“ ^ 16.8.6”, 我只是试图渲染一个按钮,并在帖子标题中得到错误
我尝试安装npm对等依赖项
import React, { Component } from "react";
import Link from "@material-ui/core/Link";
class Welcome extends Component {
render() {
return (
<div className="Welcome">
<p>This is your public-facing component.</p>
<Link
component="button"
variant="body2"
onClick={() => {
alert("I'm a button.");
}}
>
Button Link
</Link>
</div>
);
}
}
export default Welcome;
我应该看到链接
调用上述组件的代码
import { BrowserRouter, Route, Link } from 'react-router-dom';
import Welcome from './Welcome';
import Secured from './Secured';
import Logout from './Logout';
import './App.css';
class App extends Component {
render() {
return (
<BrowserRouter>
<div className="container">
<ul>
<li><Link to="/">public component</Link></li>
<li><Link to="/secured">secured component</Link></li>
</ul>
<Route exact path="/" component={Welcome} />
<Route path="/secured" component={Secured} />
</div>
</BrowserRouter>
);
}
}
export default App;
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
ReactDOM.render(<App />, document.getElementById('root'));