Expo Router 有一个大多数开发者不知道的免费 API

发布: (2026年3月30日 GMT+8 09:20)
2 分钟阅读
原文: Dev.to

Source: Dev.to

概览

Expo Router 为 React Native 引入基于文件的路由,支持深度链接、类型化路由以及通用应用。

文件结构

app/
  index.tsx         # /
  about.tsx         # /about
  posts/[id].tsx    # /posts/123

使用本地搜索参数

import { useLocalSearchParams } from "expo-router";

export default function Post() {
  const { id } = useLocalSearchParams();
  return Post: {id};
}

导航链接

import { Link, router } from "expo-router";

View
router.push("/posts/123");

API 路由示例

// app/api/hello+api.ts
export function GET() {
  return Response.json({ message: "Hello" });
}

关键特性

  • 基于文件的 React Native 路由
  • 通用(iOS、Android、Web)
  • 类型安全的导航
  • 用于服务器逻辑的 API 路由

联系方式

需要大规模抓取或监控网页数据?请查看我在 Apify 上的网页抓取代理,或发送邮件至 spinov001@gmail.com 了解定制解决方案。

0 浏览
Back to Blog

相关文章

阅读更多 »