# @ecomplus/storefront-router 中文文档

规范地址：https://npmcn.com/package/%40ecomplus/storefront-router/

版本：2\.2\.1
npm 元数据更新时间：2022-04-05T06:38:25.074Z
中文译文更新时间：2026-11-13T05:58:53.987Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40ecomplus/storefront-router
原文对照：https://npmcn.com/package/%40ecomplus/storefront-router/?lang=original
项目主页：https://github.com/ecomplus/storefront-router#readme
源码仓库：https://github.com/ecomplus/storefront-router

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：1.2 MB，24 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：未声明
- 运行依赖：2 个
- peer 依赖：@ecomplus/utils ^1\.4\.1
- 首次发布：2019-07-24T21:31:14.151Z
- 最新版本发布：2020-10-07T23:28:55.803Z
- 近 30 天下载量：4178（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：23（近 12 个月 0 个）

## 中文简介

E-Com Plus 商店前端通用 JS 路由器

## 安装

```sh
npm install @ecomplus/storefront-router
```

也可以使用：`pnpm add @ecomplus/storefront-router`、`yarn add @ecomplus/storefront-router`、`bun add @ecomplus/storefront-router`

## README

# E-Com Plus 存储前端路由器

[![Publish](https://github.com/ecomplus/storefront-router/workflows/Publish/badge.svg)](https://github.com/ecomplus/storefront-router/actions?workflow=Publish) [![CodeFactor](https://www.codefactor.io/repository/github/ecomplus/storefront-router/badge)](https://www.codefactor.io/repository/github/ecomplus/storefront-router) [![npm version](https://img.shields.io/npm/v/@ecomplus/storefront-router.svg)](https://www.npmjs.org/@ecomplus/storefront-router) [![License MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

E-Com Plus 商店前端的SPA/SSR路由器

[变化](https://github.com/ecomplus/storefront-router/blob/master/CHANGELOG.md)

## 使用量

这个 `@ecomplus/storefront-router` 软件包可用于:

-   列出所有产品、品牌、类别和收藏页面 (URL路径)用于预降/SR;
-   基于 URL 路径,获取文档正文(产品,品牌,类别,收藏) 在浏览器或服务器侧以渲染页面标记;

它既适用于Node.js环境,也适用于浏览器环境.

-   [开始吧](https://developers.e-com.plus/storefront-router/module-@ecomplus_storefront-router.html)
-   [类参考](https://developers.e-com.plus/storefront-router/EcomRouter.html)

### 示例

```js
const router = new EcomRouter()
// Simple example resolving all routes
router.list()
  .then(routes => {
    routes.forEach(route => {
      console.log(route.resource)
      router.resolve(route)
        .then(context => {
          console.log(context.body)
        })
        .catch(error => { throw error })
    })
  })
  .catch(error => {
    console.error(error)
    if (error.response) {
      console.log(error.response)
    }
  })
```

### 安装

这个 _可能_ 需要但不包括 `core-js` (可选)和 [`@ecomplus/utils`](https://developers.e-com.plus/utils/) (同类依赖).

#### 网络软件包

```bash
npm i --save core-js @ecomplus/utils @ecomplus/storefront-router
```

#### 节点.js

```bash
npm i --save @ecomplus/utils @ecomplus/storefront-router
```

#### 光盘N

```html
<script src="https://cdn.jsdelivr.net/npm/@ecomplus/storefront-router/dist/ecom-router.var.min.js"></script>
```

在从CDN进口时, `ecomUtils` 财务报告和审定财务报表 `ecomClient` 图书馆 **必须单独列入** 并可在窗口瞄准镜上找到.

## 常见问题

### @ecomplus/storefront-router 是什么？

E-Com Plus 商店前端通用 JS 路由器

### 如何安装 @ecomplus/storefront-router？

在项目目录运行 npm install @ecomplus/storefront-router，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@ecomplus/utils（^1\.4\.1）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @ecomplus/storefront-router 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/ecomplus\_\_storefront-router 是否存在。

### @ecomplus/storefront-router 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @ecomplus/storefront-router 可以商用吗？

@ecomplus/storefront-router 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @ecomplus/storefront-router 的下载量有多少？

根据 npm 官方下载统计，@ecomplus/storefront-router 在 2026/10/13 – 2026/11/11 这 30 天内被下载 4,178 次，日均约 139 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @ecomplus/storefront-router 还在维护吗？

最新版本 2\.2\.1 发布于 2020/10/08（6 年前）；至今共发布 23 个版本，其中过去 12 个月发布了 0 个；首次发布于 2019/07/25。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

