Daniel15 / RouteJs

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

It returns null when the url is an empty string #37

Closed hernangm closed 8 years ago

hernangm commented 9 years ago

An empty string is a valid url resolvable from a route. However when finalUrl is an empty string, it returns null and it should return the empty string.

Daniel15 commented 9 years ago

Thanks for reporting this! Sorry for the delay in replying. I'll look into this in the new year. In the meantime, feel free to send a pull request if you resolve the issue :)

Daniel15 commented 9 years ago

Just getting back into things now. Is an empty string really a valid URL? Wouldn't it be / for the root?

hernangm commented 9 years ago

Hi Daniel,

I have the following controller

public class HomeController : Controller
{
    [HttpGet, Route("")]
    public virtual ActionResult Index()
    {
        return View();
    }
}

but when I call

Router.action("Home", "Index") in my js files I get some exception, although the route does exist in the list of registered routes as

"{"route":{"url":"","defaults":{"controller":"Home","action":"Index"},"constraints":{},"optional":[]},"_params":[],"_parsedConstraints":{}}"

I did some debugging and the problem seems to be here:

        // Try to merge all URL parameters
        // If null, this means a required parameters was not specified.
        finalUrl = this._merge(finalValues, processedParams);
        if (!finalUrl) {
            return null;
        }

When finalUrl is "", that is evaluated by !finalUrl as a truish value, returning null. I think it could be fixed if finalUrl is checked against null directly.

Daniel15 commented 8 years ago

Good catch, thanks! I'll try to take a look soon.