gpt4 book ai didi

javascript - react 路由器警告: Received `true` for a non-boolean attribute `exact`

转载 作者:行者123 更新时间:2023-12-04 11:36:50 29 4
gpt4 key购买 nike

我在使用 Prop “精确”映射按钮期间收到控制台警告:

Warning: Received true for a non-boolean attribute exact.

If you want to write it to the DOM, pass a string instead: exact="true" or 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
}
];
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;

最佳答案

用模板文字修复它:

const navigationList = TOP_LEVEL_ROUTES
.map(({ exact, path, name }) => (
<Button
component={Link}
to={path}
key={path}
exact={`${exact}`}
>
{name}
</Button>

关于javascript - react 路由器警告: Received `true` for a non-boolean attribute `exact` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55967080/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com