useMatches

useMatches

返回页面上当前匹配的路由。这对于使用当前路由创建布局抽象很有用。

¥Returns the current route matches on the page. This is useful for creating layout abstractions with your current routes.

function SomeComponent() {
  const matches = useMatches();

  // ...
}

matches 的结构如下:

¥matches has the following shape:

[
  { id, pathname, data, params, handle }, // root route
  { id, pathname, data, params, handle }, // layout route
  { id, pathname, data, params, handle }, // child route
  // etc.
];

其他资源

¥Additional Resources

Remix v2.17 中文网 - 粤ICP备13048890号