getCurrentPages()

版本要求:
@ray-js/ray≥0.2.0

描述

获取当前页面栈。返回一个数组,数组中的元素为页面栈中的页面对象,数组第一个元素为首页,最后一个元素为当前页面。

参数

无

返回值

类型:PageInstance[]
页面栈数组,每个元素为 PageInstance 对象

示例代码

基础用法

import React from 'react';
import { View, Button, getCurrentPages } from '@ray-js/ray';

export default function Home() {
  const handleGetPages = () => {
    const pages = getCurrentPages();
    console.log('当前页面栈长度:', pages.length);
    console.log('当前页面:', pages[pages.length - 1]);

    pages.forEach((page, index) => {
      console.log(`页面 ${index}:`, page.route);
    });
  };

  return (
    <View style={{ padding: 20 }}>
      <Button onClick={handleGetPages}>获取页面栈</Button>
    </View>
  );
}