AngularJS:具有可选参数的URL路径选择 [英] AngularJS: Routing with URL having optional parameters

查看:177
本文介绍了AngularJS:具有可选参数的URL路径选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在含路线我app.js的URL。可以说,网址是:

  / API /:OPT1 /:OPT2 /:OPT3 /用户

我想,我的网址在任何情况下工作,我应该能够忽略的可选参数(OPT1,OPT2或OPT3,可能是所有或少数)。我怎样才能做到这一点。

有什么办法,我可以打电话 $ location.path('/用户),我也可以指定哪些可选参数的值<? / p>

解决方案

可选路由参数都标有 ,是这样的:

 `/用户/:ID`?

然后这条路既 /用户和匹配 /用户/ 1 路径

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?

解决方案

Optional route parameters are marked with ?, like this:

`/users/:id?`

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

这篇关于AngularJS:具有可选参数的URL路径选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆