AngularJS UI Router: Route conflict because of optional parameter

前端 未结 2 643
暖寄归人
暖寄归人 2021-01-20 16:26

I have a couple of routes in my AngularJS app, I\'m using UI-Router for routing between states/pages in my site. An issue I am having is that I have conflicting routes becau

2条回答
  •  青春惊慌失措
    2021-01-20 17:21

    Best practice would say that this should probably be a query string parameter rather than a route parameter since you are using it to filter out data. To do this with ui-router just define it like so:

    $stateProvider
    .state('home', {
       url: '/?filter'
    });
    

    Now just do

    $state.go('home', {filter: 'apples'})
    

提交回复
热议问题