angularjs - AngulrJS optional route parameter in the beginning -


i'm trying configure angular app optional route parameter.

the urls need support may have locale @ beginning. e.g.

  • /fr-fr/welcome
  • /welcome

i tried following

$routeprovider.when('/:locale?/welcome', { ... }) 

however, seems, satisfies "/fr-fr/welcome" case , not "/welcome" case.

is because i'm prepending "/" in beginning.

will following work?

$routeprovider.when('/:locale/?welcome', { ... }) 

https://docs.angularjs.org/api/ngroute/service/$route#example

.config(function($routeprovider, $locationprovider) {       $routeprovider        .when('/book/:bookid', {         templateurl: 'book.html',         controller: 'bookcontroller',         resolve: {          }       })       .when('/book/:bookid/ch/:chapterid', {         templateurl: 'chapter.html',         controller: 'chaptercontroller'       }); 

also can use multiple language support tutorials

https://scotch.io/tutorials/internationalization-of-angularjs-applications


Comments