Daniel15 / RouteJs

JavaScript URL routing for ASP.NET MVC and WebForms
84 stars 19 forks source link

Exception when handling custom constraints #32

Closed Daniel15 closed 10 years ago

Daniel15 commented 10 years ago

Received via email:

Some of our routes use custom constraints. When these are parsed in the _parseConstraints methods in router.js, an exception occurs. The methods performs a replace action on this.route.constraints[key], but in the case I am looking at, this.route.constraints[key] is an (empty) object.

Daniel15 commented 10 years ago

This has been fixed in the 1.1.7 release. Thanks for reporting!

stijnherreman commented 10 years ago

Just ran into the issue myself. If I understand correctly, the fix is fine if the route parameters do not match the route. When the route parameters do match the route, RouteJs will generate an incorrect URL.

There's no way for RouteJs to fix this, but perhaps a console warning can be generated when a route with custom constraints is used? It would make developers aware so that they can try to work around the issue.

I could be wrong entirely though, I'll see if I can create a proof of concept where the fix causes an issue.

Daniel15 commented 10 years ago

Yeah, please create another issue if you can make a self-contained proof of concept. I don't use custom constraints myself, and haven't really seem them very widely used.