Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/villander/ember-engines-router-service
Provides the Router service for ember-engines
https://github.com/villander/ember-engines-router-service
ember-addon ember-engines emberjs routing service
Last synced: 4 days ago
JSON representation
Provides the Router service for ember-engines
- Host: GitHub
- URL: https://github.com/villander/ember-engines-router-service
- Owner: villander
- License: mit
- Created: 2020-03-25T21:05:22.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-07-10T02:25:16.000Z (6 months ago)
- Last Synced: 2024-10-30T00:16:18.759Z (about 2 months ago)
- Topics: ember-addon, ember-engines, emberjs, routing, service
- Language: JavaScript
- Homepage:
- Size: 902 KB
- Stars: 14
- Watchers: 3
- Forks: 6
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ember-engines-router-service
[![npm version](https://badge.fury.io/js/ember-engines-router-service.svg)](https://badge.fury.io/js/ember-engines-router-service)
[![Build Status](https://github.com/villander/ember-engines-router-service/workflows/CI/badge.svg)](https://github.com/villander/ember-engines-router-service/actions?query=workflow%3ACI)This addon provides an API for authoring a [Router service](https://api.emberjs.com/ember/release/classes/RouterService) used in ember-engines.
## Compatibility
- Ember.js v3.24 or above
- Embroider or ember-auto-import v2## Installation
```
ember install ember-engines-router-service
```## Usage
Basically you have the full [RouterService](https://api.emberjs.com/ember/release/classes/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.
```js
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](https://github.com/emberjs/rfcs/pull/122).
## TypeScript
The library ships types for TypeScript usage:
```ts
import Service, { inject as service } from '@ember/service';
import type EnginesRouterService from 'ember-engines-router-service/services/router';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](CONTRIBUTING.md) guide for details.
## License
This project is licensed under the [MIT License](LICENSE.md).