你们中的任何人在react-router-dom上使用树状摇动时是否遇到此错误?
这是我的代码
<html>
<head>
<style>
.box {
padding: 50px;
width: auto;
}
.clearfix{
display: flex;
width: 100%;
}
</style>
</head>
<body>
<div class="clearfix">
<div class="box" style="background-color:#bbb"> <-- needs to be auto size in case more are added or removed -->
<p>Some text inside the box.</p>
</div>
<div class="box" style="background-color:#ccc">
<p>Some text inside the box.</p>
</div>
</div>
</body>
</html>
我收到一个错误import React, { Component } from 'react'
import Link from 'react-router-dom/Link';
import AppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import Button from '@material-ui/core/Button';
export class Navbar extends Component {
render() {
return (
<AppBar>
<Toolbar className="nav-container">
<Button color="inherit" component={Link} to={'/'}>Home</Button>
<Button color="inherit" component={Link} to={'/signup'}>Signup</Button>
<Button color="inherit" component={Link} to={'/login'}>Login</Button>
</Toolbar>
</AppBar>
)
}
}
这是Web应用程序依赖项的当前版本。
Warning: Please use `require("react-router-dom").Link` instead of `require("react-router-dom/Link")`. Support for the latter will be removed in the next major release.
答案 0 :(得分:0)
正确的导入是
import { Link } from 'react-router-dom';