Add `.url` getter to `RouteInfo`
- Dominant language
- No language data
- Stars
- 801
- Forks
- 409
- PR merge metrics
- No merged PRs in 30d
Description
Currently generating a URL for a `RouteInfo` object requires quite a bit of manual, repetitive plumbing:
```ts
/**
* Retrieves all parameters for a `RouteInfo` object and its parents in
* correct oder, so that you can pass them to e.g.
* `transitionTo(routeName, ...params)`.
*
* @param routeInfo
*/
getParameters(routeInfo: RouteInfo): string[] {
let allParameters: string[] = [];
let current: RouteInfo | null = routeInfo;
do {
const { params, paramNames } = current;
const currentParameters = paramNames.map(n => params[n] as string);
allParameters = [...currentParameters, ...allParameters];
} while ((current = current.parent));
return allParameters;
}
/**
* Builds the URL for a `RouteInfo` object and its parents.
*
* @param routeInfo
*
* {@link https://github.com/emberjs/rfcs/issues/658}
*/
getURLFromRouteInfo(routeInfo: RouteInfo): string {
const { name, queryParams } = routeInfo;
const orderedParameters = this.getParameters(routeInfo);
const url = this.router.urlFor(name, ...orderedParameters, { queryParams });
return url;
}
```
I would like to expose this as a `get url()` directly on `RouteInfo` instead.
I haven't looked deeply into the code for `RouteInfo` yet, but I guess that it's basically a passthrough of [`router.js/lib/router/route-info.ts`](https://github.com/tildeio/router.js/blob/master/lib/router/route-info.ts) somewhere, so it may possibly lack an owner, which could make things a bit more complicated, but maybe it would also allow to completely avoid using the `RouterService` in the first place.
Would this feature be appreciated? Does it require a fully-fledged RFC?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.