# @retailwe/common-libs-navigator

> RetailWe libs

Latest version **0.0.3** (published 2020-11-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install @retailwe/common-libs-navigator
pnpm add @retailwe/common-libs-navigator
yarn add @retailwe/common-libs-navigator
bun add @retailwe/common-libs-navigator
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2020-11-02 |
| First published | 2020-08-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=8.9 |
| Dependencies | 1 |
| Unpacked size | 50.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | gaterking, jeannehuang, jerryc |

## Links

- npm: https://www.npmjs.com/package/@retailwe/common-libs-navigator
- Repository: git@git.code.tencent.com:tencent-retail-fe/retailwe
- npm.io page: https://npm.io/package/@retailwe/common-libs-navigator

## Dependencies (1)

- [@retailwe/common-libs-logger](https://npm.io/package/@retailwe/common-libs-logger.md) ^0.0.3

## Recent versions

- 0.0.3 (latest) — 2020-11-02
- 0.0.1-alapha.1 (beta) — 2020-08-13
- 0.0.2 — 2020-09-01
- 0.0.1 — 2020-08-13
- 0.0.1-alapha.0 — 2020-08-13

## README

# Navigator 导航器

## Feature

1. 防抖
2. 最大页面栈处理
3. Tabbar 页面处理

## 安装

```shell
yarn add '@retailwe/common-libs-navigator' --save-exact
```

## 使用 `gotoPage`

**定义：**

```javascript
function gotoPage(path, query, options);
```

**使用：**

```javascript
import Navigator from '@retailwe/common-libs-navigator';

const navigator = new Navigator();

navigator.gotoPage('/pages/home/index', { name: 'retailwe' });
```

**策略说明**

1. 防抖：短时间多次调用，只触发一次
2. 最大页面栈处理：
   1.  目标页面存在页面栈中，页面出栈只到目标页面处于栈顶（`wx.navigateBack`）
   2. 目标页面不在页面栈中，出栈第一个页面，压入目标页面（`wx.redirect`）
3. Tabbar 页面处理：清除页面栈，压入目标页面（`wx.switchTab`）

**显式 Redirect**

```javascript
navigator.gotoPage(
  '/pages/home/index',
  { name: 'retailwe' },
  { redirect: true }
);
```

**Tabbar 页面跳转**

由于目前还没有比较成熟的判断跳转页面是 Tabbar 页面的方式，需要调用时显式传递

```javascript
import { Navigator, PathType } from '@retailwe/common-libs-navigator';

const navigator = new Navigator();

navigator.gotoPage({
  path: '/pages/home/index',
  type: PathType.TAB
});
```

## 结合 RouterMap

```javascript
import { PathType, Navigator } from '@retailwe/common-libs-navigator';

// 维护路由映射表
const routes = {
  home: {
    path: '/pages/home/index',
    type: PathType.TAB
  },
  log: {
    path: '/pages/log/index',
    type: PathType.NORMAL
  }
};

const navigator = new Navigator();

navigator.gotoPage(routes.home);
```

## 单元测试覆盖率

[单元测试覆盖率](cov/index.html)

---
_Source: https://npm.io/package/@retailwe/common-libs-navigator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
