Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid absolute route url generated by a child router #606

Closed
matik12 opened this issue Jun 21, 2018 · 0 comments
Closed

Invalid absolute route url generated by a child router #606

matik12 opened this issue Jun 21, 2018 · 0 comments
Assignees
Labels

Comments

@matik12
Copy link

matik12 commented Jun 21, 2018

I'm submitting a bug report

Library Version:
1.6.1

Current behavior:
When you generate absolute url for a route that is registered globally in AppRouter and you are using a ChildRouter for url generation i.e.

// router is injected into component, in this case it's a child router
this.router.generate('global-route', null, { absolute: true });

The following code will not generate an absolute url, but only a relative url i.e. /some-route/something.

Expected/desired behavior:
Expected behaviour is to have an absolute url generated by router.generate method i.e. https://some-domain.com/some-route/something or http://localhost:9000/some-route/something.

Issue investigation:
In router.js file there is a method generate used for this purpose. Issue is in line 274 => Router line 274 . When the route is not found in the current router (in this case a child router), generate method is invoking itself on the parent router to find this route in his configuration.

generate(name: string, params?: any, options?: any = {}): string {
    let hasRoute = this._recognizer.hasRoute(name);
    if ((!this.isConfigured || !hasRoute) && this.parent) {
      return this.parent.generate(name, params);
    }

    if (!hasRoute) {
      throw new Error(`A route with name '${name}' could not be found. Check that \`name: '${name}'\` was specified in the route's config.`);
    }

    let path = this._recognizer.generate(name, params);
    let rootedPath = _createRootedPath(path, this.baseUrl, this.history._hasPushState, options.absolute);
    return options.absolute ? `${this.history.getAbsoluteRoot()}${rootedPath}` : rootedPath;
}

The method call below doesn't pass options parameter, thus url generated by a parent router is not absolute, because options object is an empty object literal.

return this.parent.generate(name, params);

Seems that this issue could be fixed by adding missing parametr to the method call

return this.parent.generate(name, params, options);
@davismj davismj self-assigned this Jul 10, 2018
@davismj davismj added the bug label Jul 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants