前言
最近在写RN项目,浅浅记录一下react navigation的嵌套路由实现
大概实现效果如下
与一般的APP不同的是没有底部Tab而是换成了顶部菜单。
一、安装相关包
npm install @react-navigation/native
npm install react-native-screens react-native-safe-area-context
npm install @react-navigation/native-stack
二、编写菜单组件 Menu
import React from "react"
import {
View, Image, Text, ScrollView } from "react-native"
import {
getFocusedRouteNameFromRoute } from "@react-navigation/native"
import {
LinkButton } from "./LinkButton"
export const Menu = React.memo(({
route }) => {
const routeName = getFocusedRouteNameFromRoute(route) ?? "Home"
return (
<View className="flex-row items-center bg-blue-light text-white pt-36">
<Image source={
require("../images/logo.png")} style={
{
width: 50, height: 40 }} resizeMode={
"cover"} />
<Text className={
"text-white text-lg font-bold mx-10 mr-20"}>桌面管理系统</Text>
<ScrollView horizontal={
true} showsHorizontalScrollIndicator={
false} showsVerticalScrollIndicator={
false}