---
title: getCurrentPages
summary: "介绍 getCurrentPages() 函数的用法，用于获取当前页面栈信息。"
questions:
  - getCurrentPages() 的返回值是什么格式？
  - 页面栈数组中第一个和最后一个元素分别代表什么？
  - 为什么不能修改 getCurrentPages() 返回的页面栈？
  - 为什么不能在 App.onLaunch 中调用 getCurrentPages()？
  - 如何通过 getCurrentPages() 获取当前页面的路径？
---

## getCurrentPages(): PageObject[]

获取当前页面栈。数组中第一个元素为首页，最后一个元素为当前页面。

**注意事项**

- **不要尝试修改页面栈，会导致路由以及页面状态错误。**
- 不要在 `App.onLaunch` 的时候调用 `getCurrentPages()`，此时 `page` 还没有生成。

## 示例

```js
// page/index.js
Page({
  onLoad() {
    const pageInsts = getCurrentPages();
    const currentPagePath = pageInsts[pageInsts.length - 1].route;
    console.log('currentPagePath ===> ', currentPagePath);
  },
});
```
