4

I have this rule in my app.js:

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

When user type a url like: /en/rental-houses-santa-cruz-tenerife

Then:

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

When my expected result is:

type = houses
departure = santa-cruz-tenerife

Is there any way to achieve this?

Rober
  • 5,868
  • 17
  • 58
  • 110
  • It very hard to predict by `router engine` to take value upto which `-`(hyphen).. Plunkr here http://plnkr.co/edit/1BDG9C0r0f8mrcCQeJYT?p=preview – Pankaj Parkar Dec 11 '15 at 19:41
  • Is there a reason why you do not use slash character to separate type and departure? like *.../en/rental/houses/santa-cruz-tenerif* ? – Rémi Bantos Dec 12 '15 at 20:58

1 Answers1

1

Upgrade to angular 1.2 to do this.

The standard way of handling this in angular is through ngRoute and regular expressions (like is shown here and here's a plunker), but angular 1.0.8 doesn't allow you to use regular expressions at all in the route patterns (see here, ctrl+f for switchRouteMatcher).

You could fork angular 1.0.8 and add update the switchRouteMatcher method too if upgrading your version to 1.2 is out of the question.

Community
  • 1
  • 1
caleb
  • 126
  • 4
  • Thanks for the answer. Upgrade to Angular 1.2 is not an option right now. I had a look at switchRouteMatcher but honestly at first sight looks chinese to me. I´m also afraid to update that core code. Any help or other idea is appreciated. – Rober Dec 16 '15 at 20:57
  • Yeah, just compare it to the same method in Angular 1.2 - it looked like only a couple lines are different, and then you'll be able to take advantage of that `.regexp` property like in the examples. – caleb Dec 17 '15 at 02:57