我正在尝试使用包含路径和id的对象数组创建页码组件。
import React from 'react';
export function PageNumber(props) {
const pageData = [
{path: '/calc/1', id:1},
{path: '/calc/2', id:2},
{path: '/calc/3', id:3},
{path: '/calc/4', id:4},
{path: '/calc/5', id:5},
{path: '/calc/6', id:6},
{path: '/calc/7', id:7}
]
const CurrentPage = props.location.pathname;
const numberOfPages = pageData.length;
如何映射数组并仅显示当前页面?
return (
<div>{
pageData.map(page => {
page.path == CurrentPage ? page.path : ''
<span>{page.path} of {numberOfPages}</span>
})}
</div>
);
}