Should a global/star route segment drop the trailing '/'?



Glob/star segments that are at the end of the URL have the trailing / removed. This seems incorrect. Is this a desired behavior?

More Info

I’ve been using a glob/star segment to enable a file-browser interface, which requires the path to be part of the URL.

The router would look similar to this: {
  this.resource("files", function(){
    this.route("path", {path: "/*path"});

The glob/star segment (undocumented, but discussed here and initially added to ember in this pr) works almost perfectly for this use-case. The only problem is the trailing / is stripped. For example, given this URL:


the path parameter would be

path/to/the/files      <- no '/' at the end!

I would prefer to use the trailing / to detect whether a file or a folder has been specified, but that isn’t possible without manually accessing the original URL.

Why this happens

I dug into the part of the router that deals with the segments (route-recognizer) and found that trailing /s are purposefully removed (this commit) to make sure that static and dynamic routes are correctly matched. This is not a requirement If the last segment is a glob/star segment, and since a glob/star segment is supposed to be a catch-all I feel that the entire segment should be captured, including the trailing /.

How to fix this

In my current implementation I grab the entire original URL hash from window.location.hash to check if the last character is a /, but this seems extremely hacky/fragile/not a good idea and I would like to just check the path parameter.

I filed this as an issue in the Emberjs Github issue tracker and submitted a PR to route-recognizer to leave the trailing slash if the last segment is a glob/star segment.

Anyone have any ideas on whether this should be the behavior?