AngularJS: Routing with URL having optional parameters

允我心安 提交于 2019-12-10 16:09:30

问题


I have a URL in my app.js containing routes. lets say the url is:

/api/:opt1/:opt2/:opt3/users

I want that my url will work in any case, i should able to ignore the optional parameters (opt1, opt2 or opt3, may be all or few). How can I achieve this.

Is there any way that I can call $location.path('/users'), and I can specify also what are the values of the optional parameters?


回答1:


Optional route parameters are marked with ?, like this:

`/users/:id?`

Then this route matches both /users and /users/1 paths



来源:https://stackoverflow.com/questions/23027273/angularjs-routing-with-url-having-optional-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!