0

I have some old routes I would like to support in angular like that:

/2345.aspx
/4321.aspx
/123.aspx

Is there a way to map that with $routeprovider?

Something like:

 .when('/{path:.aspx}', {
    templateUrl : 'src/ng-app/views/posts/post.html',
        controller : 'postController'
    })
jenson-button-event
  • 18,101
  • 11
  • 89
  • 155

3 Answers3

1

This code example use ui-router:

'use strict';

var states = function ($stateProvider, $urlRouterProvider) {

  $stateProvider
    .state('main.post', {
      url: '/:postId' + '.aspx',
      templateUrl: 'src/ng-app/views/posts/post.html',
      controller: 'PostCtrl'
    });
};

states.$inject = [
  '$stateProvider',
  '$urlRouterProvider'
];
Huy Chau
  • 2,178
  • 19
  • 26
0

That just works:

.when('/:path.aspx', {
     templateUrl : 'src/ng-app/views/posts/post.html',
     controller : 'postController'
})
jenson-button-event
  • 18,101
  • 11
  • 89
  • 155
  • That's what I thought, too, but the documentation says: *path can contain named groups starting with a colon: e.g. :name. All characters up to the next slash are matched and stored in $routeParams under the given name when the route matches.*. So if the documentation is correct, it shouldn't just work. – JB Nizet Jun 14 '16 at 08:38
0

It is always preferred to use ui-router over ng-router, which is more capable of handling states. Please refer the below link for more details on the difference between both.

What is the difference between angular-route and angular-ui-router?

Community
  • 1
  • 1
Aravind
  • 2,290
  • 1
  • 11
  • 21