@bagaar/ember-breadcrumbs

中文文档
6.0.0发布于 2026/08/20MITTypeScriptCommonJS近 30 天下载 5067

Template based breadcrumb management for Ember applications.

原始使用文档
文档目录14 节
  1. Compatibility
  2. Installation
  3. Usage
  4. Registering the breadcrumbs Service
  5. Strict mode example (GJS)
  6. 1. Defining Where You Want the Breadcrumbs to Be Rendered
  7. 2. Leaving Behind Breadcrumbs
  8. 3. Styling the Breadcrumbs
  9. 4. <BreadcrumbsContainer /> arguments
  10. Usage Inside an Engine
  11. 1. Add @bagaar/ember-breadcrumbs to Your Engine's dependenc…
  12. 2. Make the breadcrumbs Service Available Inside the Engine
  13. Contributing
  14. License

@bagaar/ember-breadcrumbs

CI NPM Version

Template based breadcrumb management for Ember applications.

Compatibility

  • Ember.js v5.8 or above
  • Embroider or ember-auto-import v2

Installation

npm install -D @bagaar/ember-breadcrumbs
pnpm add -D @bagaar/ember-breadcrumbs
yarn add -D @bagaar/ember-breadcrumbs

Usage

Registering the breadcrumbs Service

Classic apps don't have to do anything: the breadcrumbs service is re-exported into the app tree automatically.

Apps using a strict resolver have to register the service themselves, because there is no app-tree re-export to resolve it for them:

// app/app.js

import BreadcrumbsService from '@bagaar/ember-breadcrumbs/services/breadcrumbs';

export default class App extends Application {
  modules = {
    './services/breadcrumbs': BreadcrumbsService,
    // ...
  };
}

See demo-app/app.gts for a working example.

Strict mode example (GJS)

If you are using strict mode templates, import the components and use them directly in your template block. The same pattern applies to GTS files.

// app/components/breadcrumbs-demo.gjs

import Component from '@glimmer/component';
import { LinkTo } from '@ember/routing';
import { BreadcrumbsContainer, BreadcrumbsItem } from '@bagaar/ember-breadcrumbs/components';

export default class BreadcrumbsDemo extends Component {
  <template>
    <BreadcrumbsContainer
      @itemClass="breadcrumbs__item"
      @linkClass="breadcrumbs__link"
      class="breadcrumbs"
    />

    <BreadcrumbsItem as |linkClass|>
      <LinkTo @route="foo" class={{linkClass}}>
        Foo
      </LinkTo>
    </BreadcrumbsItem>

    <BreadcrumbsItem as |linkClass|>
      <LinkTo @route="foo.bar" class={{linkClass}}>
        Bar
      </LinkTo>
    </BreadcrumbsItem>
  </template>
}

1. Defining Where You Want the Breadcrumbs to Be Rendered

{{! app/templates/application.hbs }}

<BreadcrumbsContainer
  @itemClass="breadcrumbs__item"
  @linkClass="breadcrumbs__link"
  class="breadcrumbs"
/>

NOTE: It's also possible to render multiple instances of the <BreadcrumbsContainer /> component.

2. Leaving Behind Breadcrumbs

{{! app/templates/foo.hbs }}

<BreadcrumbsItem as |linkClass|>
  <LinkTo @route="foo" class={{linkClass}}>
    Foo
  </LinkTo>
</BreadcrumbsItem>
{{! app/templates/foo/bar.hbs }}

<BreadcrumbsItem as |linkClass|>
  <LinkTo @route="foo.bar" class={{linkClass}}>
    Bar
  </LinkTo>
</BreadcrumbsItem>

NOTE: The <BreadcrumbsItem /> component is responsible for rendering the provided <LinkTo /> component into all instances of the <BreadcrumbsContainer /> component using Ember's {{in-element}} helper.

Advantages

Leaving behind breadcrumbs like this might seem very verbose, but it's actually pretty flexible and has some advantages:

  1. Because you leave behind breadcrumbs inside templates, the addon doesn't have to take async model hooks into account
  2. Because you use Ember's <LinkTo /> component to define breadcrumb links, you have complete control over:
    • how you define them (inline vs. block)
    • how they should work (route, dynamic segments, query parameters, ...)
    • how they should look like (text, icons, additional CSS class names, ...)

Rendered Output

The rendered output will be:

<ul class="breadcrumbs">
  <li class="breadcrumbs__item">
    <a class="breadcrumbs__link" href="/foo">Foo</a>
  </li>
  <li class="breadcrumbs__item">
    <a class="breadcrumbs__link" href="/foo/bar">Bar</a>
  </li>
</ul>

3. Styling the Breadcrumbs

The addon doesn't ship with default styling, this should be done inside the consuming project.

4. <BreadcrumbsContainer /> arguments

NameDescriptionType
itemClassThe class that will be added to all <BreadcrumbsItem /> componentsString
linkClassThe class that will be yielded to the <BreadcrumbsItem />'s block contentString

Usage Inside an Engine

1. Add @bagaar/ember-breadcrumbs to Your Engine's dependencies

This will make all @bagaar/ember-breadcrumbs components available inside the engine.

{
  "dependencies": {
    "@bagaar/ember-breadcrumbs": "*"
  }
}

2. Make the breadcrumbs Service Available Inside the Engine

This will make sure that the same instance of the breadcrumbs service is used inside the engine and inside the host application.

// app/app.js

export default class App extends Application {
  engines = {
    'engine-name': {
      dependencies: {
        services: ['breadcrumbs'],
      },
    },
  };
}
// lib/engine-name/addon/engine.js

export default class EngineName extends Engine {
  dependencies = {
    services: ['breadcrumbs'],
  };
}

That's it! Now you should be able to leave behind breadcrumbs inside the engine and render them inside the host application.

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

版本与发布记录

@bagaar/ember-breadcrumbs 共发布 15 个版本,首次发布于 2018/10/21;过去 12 个月发布了 1 个版本。

版本发布日期距今
6.0.0latest2026/08/202 个月前
5.1.02025/04/161.6 年前
5.0.02024/03/052 年前
4.1.02023/07/053 年前
4.0.02022/10/214 年前
3.0.02022/06/234 年前

关于 @bagaar/ember-breadcrumbs 的常见问题

@bagaar/ember-breadcrumbs 是什么?

Template based breadcrumb management for Ember applications.

如何安装 @bagaar/ember-breadcrumbs?

在项目目录运行 npm install @bagaar/ember-breadcrumbs,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:ember-modifier(>= 4.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bagaar/ember-breadcrumbs 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bagaar/ember-breadcrumbs 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@bagaar/ember-breadcrumbs 可以商用吗?

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

@bagaar/ember-breadcrumbs 的下载量有多少?

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

@bagaar/ember-breadcrumbs 还在维护吗?

最新版本 6.0.0 发布于 2026/08/20(2 个月前);至今共发布 15 个版本,其中过去 12 个月发布了 1 个;首次发布于 2018/10/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。