Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(ngRoute): change interpolation to support globbed routes #8793

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ngRoute/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ function $RouteProvider(){
if (i === 0) {
result.push(segment);
} else {
var segmentMatch = segment.match(/(\w+)(.*)/);
var segmentMatch = segment.match(/(\w+)\*?(.*)/);
var key = segmentMatch[1];
result.push(params[key]);
result.push(segmentMatch[2] || '');
Expand Down
27 changes: 27 additions & 0 deletions test/ngRoute/routeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,33 @@ describe('$route', function() {
});


it('should support globbed route updating', function() {
module(function($routeProvider) {
$routeProvider.when('/bar/:foo*', {});
$routeProvider.when('/baz/:foo*/edit', {});
});

inject(function($rootScope, $route, $location, $routeParams) {
$location.path('/bar/multi/segment/path');
$rootScope.$digest();
expect($routeParams).toEqual({foo: 'multi/segment/path'});
$route.updateParams({foo: 'new'});
$rootScope.$digest();
expect($routeParams).toEqual({foo: 'new'});
$location.path('/baz/multi/segment/path/edit');

$rootScope.$digest();
expect($routeParams).toEqual({foo: 'multi/segment/path'});
$route.updateParams({foo: 'new'});
$rootScope.$digest();
expect($routeParams).toEqual({foo: 'new'});
$route.updateParams({foo: 'new/multi'});
$rootScope.$digest();
expect($routeParams).toEqual({foo: 'new/multi'});
});
});


it('should complain if called without an existing route', inject(function($route) {
expect($route.updateParams).toThrowMinErr('ngRoute', 'norout');
}));
Expand Down