ui-router optional param without trailing slash

后端 未结 1 1154
长情又很酷
长情又很酷 2021-02-18 16:32

So this seems like a common problem but I haven\'t found any definite answer. Basically I have a state:

.state(\'users\', {
     url: \'/example/:id\',
        t         


        
相关标签:
1条回答
  • 2021-02-18 17:20

    You can define optional URL parameters by giving them a default value in the params object, like this. squash will hide the parameter in links if it's not defined.

    .state('users', {
             url: '/example/:id',
                templateUrl: 'angular-views/example.html',
                controller: 'ExampleCtrl',
                params:  {
                  id: {
                         value: null,
                         squash: true
                      }
                    }
            });
    

    I tried this locally and it seems to work OK regardless of trailing slash.

    0 讨论(0)
提交回复
热议问题