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

Offer a way to check if a path matches any existing route #122

Open
MaKleSoft opened this issue Feb 20, 2015 · 2 comments
Open

Offer a way to check if a path matches any existing route #122

MaKleSoft opened this issue Feb 20, 2015 · 2 comments

Comments

@MaKleSoft
Copy link

In some scenarios I wanna now if crossroads.parse() has matched any routes. For example, if the path did not match any existing route, I might want to forward them to a default one. One way to provide this information would be to simply have parse() return true or false based on whether any route was matched. And/or you could provide an additional method that checks if a path matches any existing route without actually triggering the route callback if it does.

@millermedeiros
Copy link
Owner

when I need to forward to the default route I use the bypassed signal

also important to remind that signals are dispatched synchronously so you could implement your own method that returns true/false with something like:

var matched;

crossroads.bypassed.add(function() {
  matched = false;
});

function goAndCheck(path) {
  matched = true;
  crossroads.parse(path);
  return matched;
}

you can also use the internal method _getMatchedRoutes which should return an empty array if it can't match anything.

@bzin
Copy link

bzin commented Oct 23, 2015

@millermedeiros why don't you make the _getMatchedRoutes method available in the API documentation of crossroads?

I know that you use this function internally but there is no warranty that this would be maintain in the future or if it will be replaced by something else.

I believe it will be important to have documentation that this is possible. I am actually using this method but to figure it out I add to go through all crossroads.js to know its existence.

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

No branches or pull requests

3 participants