GithubHelp home page GithubHelp logo

buschtoens / ember-routing-utils Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 1.0 393 KB

Utility tools for working with the Ember `RouterService`

JavaScript 38.12% TypeScript 50.48% HTML 11.11% Handlebars 0.29%
ember emberjs ember-addon ember-routing

ember-routing-utils's Introduction

ember-routing-utils

CI npm version Download Total Ember Observer Score

Some utils for working with the Ember RouterService more effectively.

Installation

ember install ember-routing-utils

Usage

routing-utils Service

import { service, type DIRegistry } from '@ember/owner';

class {
  @service router: DIRegistry['service']['router'];
  @service routingUtils: DIRegistry['service']['routing-utils'];

  // ...
}

getParameters

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).

const { currentRoute, currentRouteName } = this.router;
const params = this.routingUtils.getParameters(currentRoute);
this.router.transitionTo(currentRouteName, ...params, currentRoute.queryParams);

getParametersWithQueryParameters

getParametersWithQueryParameters(routeInfo: RouteInfo): string[]

Same as getParameters, but also includes the final { queryParams } for convenience.

const { currentRoute, currentRouteName } = this.router;
const params = this.routingUtils.getParametersWithQueryParameters(currentRoute);
this.router.transitionTo(currentRouteName, ...params);

getURLFromRouteInfo

getURLFromRouteInfo(routeInfo: RouteInfo): string

Builds the URL for a RouteInfo object and its parents. Includes the rootURL.

const { currentRoute, currentRouteName } = this.router;
const url = this.routingUtils.getURLFromRouteInfo(currentRoute);

removeRootURL

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

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.

ember-routing-utils's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

deanmarano

ember-routing-utils's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.