implement Layout files and Stack navigation in a React Native application using Expo Router.

Stack -> a component and a template which wraps the rest of our pages.

1. The Layout File (_layout.jsx)

A layout file acts as a template that wraps all the pages within a directory. It allows you to share common UI elements (like footers or headers) across multiple screens.

image.png

import { StyleSheet, Text, View } from "react-native";
import { Slot } from "expo-router";

*const _layout = () => {
  return (
    <View style={{ flex: 1 }}>*
      <Slot />
      <Text>Footer</Text>
    *</View>
  );
};*

*export default _layout;

const styles = StyleSheet.create({});*

the footer keyword you can see here ————————→

1000476195.jpg


2. Stack Navigation

While Slot simply renders the page, the <Stack /> component provides a "Native" navigation experience.

*import { StyleSheet, Text, View } from "react-native";
import React from "react";*
import { Stack, Slot } from "expo-router";

*const _layout = () => {
  return (
    <View style={{ flex: 1 }}>*
      <Stack />
      <Text>Footer</Text>
    *</View>
  );
};

export default _layout;

const styles = StyleSheet.create({});*

1000476193.jpg

1000476194.jpg

image.png