Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/buschtoens/ember-routing-utils
Utility tools for working with the Ember `RouterService`
https://github.com/buschtoens/ember-routing-utils
ember ember-addon ember-routing emberjs
Last synced: 3 months ago
JSON representation
Utility tools for working with the Ember `RouterService`
- Host: GitHub
- URL: https://github.com/buschtoens/ember-routing-utils
- Owner: buschtoens
- Created: 2020-09-14T08:28:06.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-12-15T02:33:00.000Z (about 1 year ago)
- Last Synced: 2024-04-09T22:23:38.138Z (10 months ago)
- Topics: ember, ember-addon, ember-routing, emberjs
- Language: TypeScript
- Homepage:
- Size: 384 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# ember-routing-utils
[![CI](https://github.com/buschtoens/ember-routing-utils/workflows/CI/badge.svg)](https://github.com/buschtoens/ember-routing-utils/actions)
[![npm version](https://badge.fury.io/js/ember-routing-utils.svg)](http://badge.fury.io/js/ember-routing-utils)
[![Download Total](https://img.shields.io/npm/dt/ember-routing-utils.svg)](http://badge.fury.io/js/ember-routing-utils)
[![Ember Observer Score](https://emberobserver.com/badges/ember-routing-utils.svg)](https://emberobserver.com/addons/ember-routing-utils)Some utils for working with the Ember `RouterService` more effectively.
## Installation
```sh
ember install ember-routing-utils
```## Usage
### `routing-utils` Service
```ts
import { service, type DIRegistry } from '@ember/owner';class {
@service router: DIRegistry['service']['router'];
@service routingUtils: DIRegistry['service']['routing-utils'];// ...
}
```#### `getParameters`
```ts
getParameters(routeInfo: RouteInfo): string[]
```Retrieves all parameters for a `RouteInfo` object and its parents in correct
order, so that you can pass them to e.g. `transitionTo(routeName, ...params)`.```ts
const { currentRoute, currentRouteName } = this.router;
const params = this.routingUtils.getParameters(currentRoute);
this.router.transitionTo(currentRouteName, ...params, currentRoute.queryParams);
```#### `getParametersWithQueryParameters`
```ts
getParametersWithQueryParameters(routeInfo: RouteInfo): string[]
```Same as `getParameters`, but also includes the final `{ queryParams }` for
convenience.```ts
const { currentRoute, currentRouteName } = this.router;
const params = this.routingUtils.getParametersWithQueryParameters(currentRoute);
this.router.transitionTo(currentRouteName, ...params);
```#### `getURLFromRouteInfo`
```ts
getURLFromRouteInfo(routeInfo: RouteInfo): string
```Builds the URL for a `RouteInfo` object and its parents. Includes the `rootURL`.
```ts
const { currentRoute, currentRouteName } = this.router;
const url = this.routingUtils.getURLFromRouteInfo(currentRoute);
```#### `removeRootURL`
```ts
removeRootURL(url: string): string
```Removes the `rootURL` from a URL, so that it can be used with `transitionTo()`,
because Ember handles this inconsistently. 🤡If the URL does not start with the `rootURL` or the app has no `rootURL`, this
just returns the original `url`.#### `prefixRootURL`
```ts
prefixRootURL(url: string): string
```Prefixes the `rootURL` to a URL.
If the URL already starts with the `rootURL` or the app has no `rootURL`, this
just returns the original `url`.