angularjs - How to set route precedence with ui-router? -
more specifically:
i have route myapp/about
and route myapp/:userid
how ensure ui-router matches /about before /:userid ?
you need create state 2 myapp/about will have 1 state called about & other have accepting userid parameter.
.state('about',{ url: '/myapp/about', templateurl: 'appp/views/about.html', controller: 'aboutcontroller' }) .state('userdetails',{ url: '/myapp/:userid', templateurl: 'appp/views/userdetails.html' controller: 'userdetailscontroller' }) by defining them different state ui-router call about statestate when /myapp/about url appears in browser, when url other /myapp/about appears in browser call userdetails state accept userid part after /myapp/ parameter value using $stateparams service.
for making more better add regex on route ask number or can set regx there, suppose want accept number 3 digits change url option of state url: "/myapp/{userid:[0-9]{1,3}}", giving url in state load state if state has number 3 digits 123,111,etc.
Comments
Post a Comment