Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug #80

Open
Artod opened this issue Aug 18, 2014 · 1 comment
Open

Bug #80

Artod opened this issue Aug 18, 2014 · 1 comment

Comments

@Artod
Copy link

Artod commented Aug 18, 2014

Path.map('#/category/:cid/sort/:sort').to(function() {
    alert('Right!');
});

Path.rescue(function() {
    alert('Rescue!');
});

go to '#/category/12/sort/category)' or '#/category/12/sort/sort)' and as a result we will have alert 'Rescue!'

@gbalthasar
Copy link

Manually patch the Path.match function to this:

'match': function (path, parameterize) {
        var params = {}, route = null, possible_routes, slice, i, j, compare, sliceParts, compareParts;
        for (route in Path.routes.defined) {
            if (route !== null && route !== undefined) {
                route = Path.routes.defined[route];
                possible_routes = route.partition();
                for (j = 0; j < possible_routes.length; j++) {
                    slice = possible_routes[j];
                    compare = path;
                    if (slice.search(/:/) > 0) {
                        sliceParts = slice.split("/");
                        for (i = 0; i < sliceParts.length; i++) {
                            compareParts = compare.split("/");
                            if ((i < compareParts.length) && (sliceParts[i].charAt(0) === ":")) {
                                params[sliceParts[i].replace(/:/, '')] = compareParts[i];
                                compareParts[i] = sliceParts[i];
                                compare = compareParts.join('/');
                            }
                        }
                    }
                    if (slice === compare) {
                        if (parameterize) {
                            route.params = params;
                        }
                        return route;
                    }
                }
            }
        }
        return null;
    }

This solves any issue with parameter values that are in any part of the path already (like '#/category/12/sort/sort' or '#admin/edit/a').
I may have time to contribute a pull request, don't know yet

Greetings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants