目录正文在哪里可以定义 handle?在根路由定义在页面 _index 路由中与 useMatch 一起match 数组使用场景正文 Remix handle 函数是一个有用的对外
Remix handle 函数是一个有用的对外输出的 Route 模块对象,用于暴露特定的数据 match 对象,它们经常在一起使用。
当前 Remix 版本:1.15.0
import { /.../ } from "@remix-run/React";
// 根路由 handle 配合页面中 useMatches 获取到 app 数据
export const handle = {
app: 1
}
export default function App() {
return (
<html lang="en">
// ...
</html>
);
handle 与 useMatch 一起使用, useMatch 返回路由匹配相关的对象:
import type { V2_MetaFunction } from "@remix-run/node";
// hooks
import { useMatches } from "@remix-run/react";
export const meta: V2_MetaFunction = () => {
return [{ title: "New Remix App" }];
};
// 输出定义 handle 对象
export const handle = {
test: 1,
}
export default function Index() {
const match = useMatches()
console.log(match[1].test) // 在 match 中访问 match 函数
return (
<div>
<h1>Welcome to Remix</h1>
</div>
);
}
match 是一个数组, 数组中的对象数据结构:
match 一般是一个数组,会有两个对象:
当路由中需要指定一些特定的数据的时候
export const handle = { i18n: "login" };
i18n 提供给 Remix-i18n 用于根据当前路由匹配。
引用
以上就是Remix 路由模块输出对象handle函数的详细内容,更多关于Remix 路由模块handle的资料请关注编程网其它相关文章!
--结束END--
本文标题: Remix 路由模块输出对象handle函数
本文链接: https://www.lsjlt.com/news/208565.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-12
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0