flatiron / director

a tiny and isomorphic URL router for JavaScript

Home Page:http://github.com/flatiron/director

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Router not matching empty paths

Gilead opened this issue · comments

The router doesn't seem to match any route if the path is empty. For example I have a number of routes configured so http://foo.bar/#/page1 fires and http://foo.bar/# fires but neither http://foo.bar/ nor http://foo.bar does. I tried a number of more or less crazy things like:

        let routes = {
            '*'       : () : void => { /* */ },
            '.*'      : () : void => { /* */ },
            ''        : () : void => { /* */ },
            undefined : () : void => { /* */ },
            null      : () : void => { /* */ }
        };

but nothing seems to make Director fire if there is no hash at the end.

I appreciate hash-based routing is the main method of operation but I believe there should be some support for initial routes with no hash. Of note is that it seems 'notfound' handler is not fired for such routes either.

The workaround I use is to have this piece of code after all initialisation is done:

        if (window.location.pathname == '/') {
            router.setRoute('/'); // redirects from '' and '/' to '/#/'
        }

Just spotted that apparently router.init('/') does exactly what is needed.