routing - Angularjs routeprovider multiple routes lead to same view -


so, workflow angularjs $routeprovider goes following,

    $routeprovider     .when('/main1', {         templateurl: 'view1.html',     })     .when('/main2', {         templateurl: 'view2.html',     }) 

my question is, there way of simplifying following code. if when('/main1') , when('/main2') point same template. so,

    $routeprovider     .when('/main1', {         templateurl: 'view1.html',     })     .when('/main2', {         templateurl: 'view1.html',     }) 

the question asked because if have multiple languages on site, , want have multiple translations of url.

another solution recognize if site using .com or .de instance, , adjust correct /main1 or /main2 translation. instance,

var url = window.location.href; var main; if (url.match(/.de/) !== null){     main = "/main1"; }else{    main = "/main2"; }  $routeprovider .when(main, {     templateurl: 'view1.html', }) 

but semantically, doesn't seem best solution keep configuration options set in run block after config. can't inject factories (only providers, may mistaken though) config.

i go putting language first url segment in route.

$routeprovider.when('/:lng/main', {     templateurl: 'main.html',     controller: function($routeparams){         var lng = $routeparams.lng;     }     }) 

though nice if $routeprovider provide functionality url segment can isolated. ain't pretty putting :lng in each route.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -