Ill*_*huk 5 javascript reactjs react-router
我在使用道具“精确”的按钮映射期间收到控制台警告:
警告:收到
true非布尔属性exact。如果要将其写入 DOM,请改为传递字符串:exact="true" 或exact={value.toString()}。
我想我的代码没有错误
const TOP_LEVEL_ROUTES = [
{
name: 'Home',
path: HOME_URL,
component: HomeView,
exact: true
},
{
name: 'Table',
path: TABLE_URL,
component: TableView
},
{
name: 'About',
path: ABOUT_URL,
component: AboutView
}
];
Run Code Online (Sandbox Code Playgroud)
import React from 'react';
import { Link } from 'react-router-dom';
import AppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import Button from '@material-ui/core/Button';
import { LOGO_URL, HOME_URL, TOP_LEVEL_ROUTES } from 'consts';
import styles from './Header.scss';
const Header = () => {
const navigationList = TOP_LEVEL_ROUTES
.map(({ exact, path, name }) => (
<Button
component={Link}
to={path}
key={path}
exact={exact}
>
{name}
</Button>
));
return (
<AppBar className={styles.header}>
<Toolbar className={styles.headerToolbar}>
<Link to={HOME_URL}>
<img
src={LOGO_URL}
alt='FCIT logo'
/>
</Link>
<nav className={styles.headerNavbar}>
{navigationList}
</nav>
</Toolbar>
</AppBar>
);
};
export default Header;
Run Code Online (Sandbox Code Playgroud)
使用模板文字修复它:
const navigationList = TOP_LEVEL_ROUTES
.map(({ exact, path, name }) => (
<Button
component={Link}
to={path}
key={path}
exact={`${exact}`}
>
{name}
</Button>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8527 次 |
| 最近记录: |