AngularJS 1.0.7 routeParams parse

I have this rule in my app.js application:

$routeProvider.when('/:language/rental-:type-:departure', {templateUrl: 'partials/rental.html', controller: 'itemCtrl'});

When a user enters a URL, for example: /en/rental-houses-santa-cruz-tenerife

Then:

var type = $routeParams.type;     # houses-santa-cruz                                  
var departure = $routeParams.departure; # tenerife

When is my expected result:

type = houses
departure = santa-cruz-tenerife

Is there any way to achieve this?

+4
source share
1 answer

To do this, go to angular 1.2.

The standard way to handle this in angular is through ngRoute and regular expressions (for example, plunker is shown here and here ), but angular 1.0.8 does not allow you to use regular expressions at all in route patterns ( see here , ctrl + f for switchRouteMatcher).

fork angular 1.0.8 switchRouteMatcher, 1.2 .

+1

Source: https://habr.com/ru/post/1616250/


All Articles