url routing - How to handle invalid URL parameters with ui-router in AngularJS? -
url routing - How to handle invalid URL parameters with ui-router in AngularJS? -
i transitioning state state planmanager/:param param can param1, param2 or param3. utilize code navigate:
<a href ui-sref=".({state: 'param1'})" ng-click="updateresize()" ui-sref-opts="{reloadonsearch: false}">go param1 state</a>
now if somehow user hits url
parentstate/planmanager/invalidparam
, want redirect
parentstate/planmanager/param1
in planmanager module, using:
angular.module( 'parentstate.planmanager', [ 'ui.router' ]) .config(function config( $stateprovider, $urlrouterprovider) { $stateprovider["state"]( 'planmanager', { url: '/planmanager/:state', views: { "main": { controller: 'planmanagercontrol', templateurl: 'planmanager/planmanager.tpl.html' } }, data:{ pagetitle: 'plan manager', currentstate: 'planmanager'}, resolve:{ validstate: ['$stateparams','localstorageservice','$urlrouter',function($stateparams,localstorageservice,$urlrouter){ if($stateparams["state"]!="buy" && $stateparams["state"]!="audience" && $stateparams["state"]!="campaign"){ $stateparams["state"]="buy"; } homecoming true; }] } }); $urlrouterprovider.when('/planmanager/', '/planmanager/buy'); $urlrouterprovider.when('/planmanager', '/planmanager/buy'); $urlrouterprovider.otherwise('/planmanager/buy'); })
this doesn't seem work. wrong here? should using regex of sort?
angularjs url-routing state angular-ui-router
Comments
Post a Comment