Skip to content

villander/ember-engines-router-service

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

75a83e7 · Mar 26, 2024

History

76 Commits
Mar 26, 2024
Mar 26, 2024
Mar 26, 2024
Mar 26, 2024
Mar 26, 2024
Mar 26, 2024
Nov 15, 2023
Nov 2, 2023
Jan 26, 2024
Mar 26, 2024
Mar 25, 2020
Mar 26, 2024
Mar 25, 2022
Mar 26, 2024
Mar 26, 2024

Repository files navigation

ember-engines-router-service

npm version Build Status

This addon provides an API for authoring a Router service used in ember-engines.

Compatibility

  • Ember.js v3.12 or above
  • Embroider or ember-auto-import v2

Installation

ember install ember-engines-router-service

Usage

Basically you have the full RouterService API inside each engine. That means you can use APIs such as transitionTo and isActive, plus the new "external routing" APIs such as transitionToExternal and isActiveExternal which help link externalRoutes together.

import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { action } from "@ember/object";

export default class SomeComponent extends Component {
  @service router;

  @action
  transitionToHome() {
    this.router.transitionToExternal('other.route');
  }

  @action
  transitionToAdmin() {
    this.router.transitionTo('admin.route');
  }

  @action
  redirectToHome() {
    this.router.replaceWithExternal('other.route');
  }

  @action
  redirectToLogin() {
    this.router.replaceWith('login.route');
  }
}

For further documentation on this subject, view the Engine Linking RFC.

TypeScript

The library ships types for TypeScript usage:

import Service, { inject as service } from '@ember/service';
import type EnginesRouterService from 'ember-engines-router-service/services/router';

type Transition = ReturnType<EnginesRouterService['transitionTo']> & { sequence: number };

export default class MyService extends Service {
  @service declare router: EnginesRouterService;

  doSomeTranstion (): void {
    const transition = this.router.transitionToExternal('someRouter');
    transition.data.someKey = 'someValue';
  }
}

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.