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

Send back target path for easier using navigo #101

Closed
wants to merge 1 commit into from

Conversation

martonx
Copy link

@martonx martonx commented Mar 29, 2017

When we catch a navigate event, and we want to do ajax call based on the catched url, and we use just some general route like /user/:action/:id in our rooter, then we need to know what was the originally catched url, without rebuild the original url from response parameters, query strings or without any hacky other solutions). I know this is not the most elegant way, but it doesn't break anything and better then nothing. In v5 navigo should send back an object with { params, query, targetPath } instead of 3 arguments.

When we catch a navigate event, and we want to do ajax call based on the catched url, and we use just some general route like /user/:action/:id in our rooter, then we need to know what was the originally catched url, without rebuild the original url from response parameters, query strings or without any hacky other solutions). I know this is not the most elegant way, but it doesn't break anything and better then nothing. In v5 navigo should send back an object with { params, query, targetPath } instead of 3 arguments.
@krasimir
Copy link
Owner

The router already have _lastRouteResolved property that contains the latest resolved URL. I just made it available as a public method router.lastRouteResolved(). Here's a test that covers it:

describe('when we have a complex route matching', function () {
  it('should access easily the matched URL', function () {
    var handler = sinon.spy();

    router = new Navigo();
    router.on('/user/:action/:id', handler);

    router.navigate('/user/answer/42').resolve();

    expect(handler)
      .to.be.calledOnce
      .and.be.calledWith({
        action: 'answer',
        id: '42'
      }, '');
    expect(router.lastRouteResolved()).to.deep.equal({
      url: '/user/answer/42',
      query: ''
    });
  });
});

Use 4.5.0. lastRouteResolved is available there.

@krasimir krasimir closed this Mar 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants