canjs / can-route

Observable front-end application routing for CanJS.
https://canjs.com/doc/can-route.html
MIT License
10 stars 4 forks source link

deparam returns different results if leading slash is included/not #132

Open matthewp opened 6 years ago

matthewp commented 6 years ago

If you have a route like:

route("/{page}", { page: "home" });

route.deparam("/"); // { page: "home" }
route.deparam(""); // undefined

vs.

route("{page}", { page: "home" });

route.deparam("/"); // undefined
route.deparam(""); // { page: "home" }

This is not ideal, maybe we just say that you must exclude the leading slash?

mjstahl commented 6 years ago

I would go through the extra effort to allow both. Assume route("{page}") is equivalent to route("/{page}") and vice versa.

Therefore we would also have to assume that route.deparam("/") === route.deparam("")

You could, in documentation, recommend a particular way of doing things (like excluding the leading slash) but it is inevitable that someone will mess it up and not know why. And I think it is the framework's job to compensate for this sort of 'foot-gun' stuff.