Match paths with regexes #141

Closed
evanleonard opened this Issue Sep 19, 2013 · 12 comments

Projects

None yet

5 participants

@evanleonard
Contributor

Hi again, I'm trying to use the "path" parameter, but running into an issue where my paths look like "/users/5647".

is it possible today to have a path like "/users/*" that will match the above current_path?

What I'm getting right now is an infinite redirect loop =(

@sorich87
Owner

It's not possible but we'll consider it. Pull request welcome.

P.S.: I changed the issue title from How to use "path" with ids in it?.

@evanleonard
Contributor

Right, better title. It looks like you can somehow override isRedirect with a custom function today, is that true?

@sorich87 sorich87 was assigned Sep 19, 2013
@sorich87
Owner

Yes, you can do that.

@LostCrew
Collaborator

@evanleonard right after you create an instance of your tour, you can simply redefine _isRedirect with your custom function:

var tour = new Tour();

// override default method
tour._isRedirect = function() {
    // custom _isRedirect logic
};

hope it helps.

@LostCrew
Collaborator

@evanleonard are you gonna submit a pull request for the original purpose of the issue? can i instead close this issue?

@evanleonard
Contributor

Go ahead and close this. I was able to do what I need by overriding _redirect for now.

@sorich87
Owner

Why not submit a pull request? Matching with regexes is a very useful feature. ;)

@emmenko
Collaborator
emmenko commented Sep 29, 2013

I would also like to see a pull request :)

@LostCrew
Collaborator

👍 i obviously prefer to receive a shiny pull-request as well!

@evanleonard
Contributor

As would I, of course. But time is limited, and i was able to solve my issue another way for now.

FWIW, here is my workaround:

this.tour._isRedirect = function(path, currentPath) {
var isRedirect = false;
if(path != null && path !== "") {
path = path.replace(/?.*$/, "").replace(//?$/, "");
currentPath = currentPath.replace(//?$/, "");
isRedirect = currentPath.indexOf(path) != 0;
}
return isRedirect;
}

Basically is accepts any path that starts with the value of the path option on the step. Then I also needed to get the tour to sync to the right step when the user goes to the new page, so added the following method in the flow:

_syncStep: function() {
var path = document.location.pathname;
if(this.tour._current==1 && path.indexOf("/roles/") == 0) {
this.tour.goto(2);
}
else if(this.tour._current==3 && path.indexOf("/roles/") == 0) {
this.tour.goto(4);
}
else if(this.tour._current==7 && path.indexOf("/roles/") == 0) {
this.tour.goto(6);
}
},

On Sep 29, 2013, at 1:04 PM, Emanuele notifications@github.com wrote:

i obviously prefer to receive a shiny pull-request as well!


Reply to this email directly or view it on GitHub.

@sorich87 sorich87 was assigned Jan 26, 2014
@sorich87
Owner
sorich87 commented Feb 2, 2014

Fixed in 1a82a2b. You cannot set the path option to a value like ^/users/\d+$.

@sorich87 sorich87 closed this Feb 2, 2014
@luttor
luttor commented Jun 21, 2016

after redirect dont function the tour...

help me please!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment