【发布时间】:2015-10-13 13:45:33
【问题描述】:
我有一条路线 /changepassword,我需要添加 2 个参数:iduser 和 resetcode。看起来像这样:/changepassword?iduser=123&resetcode=foo
我阅读了与此相关的其他内容(1、2),但我无法弄清楚。我在 ember 方面没有任何经验,我被要求在我工作的地方做一些修改。我们正在使用 ember 1.5.1
我尝试了this,但它让我失望了:Uncaught Error: Assertion Failed: Error: Assertion Failed: The URL '/changepassword?test1=aaasd' did not match any routes in your application
[编辑]
感谢@GJK,我知道我需要的是查询参数,没有路径参数。
现在,我的代码如下所示:
路线:
module.exports = App.Router.map ->
...
...
@resource('change_password', path: '/changepassword')
控制器:
module.exports = App.ChangePasswordController = Ember.Controller.extend
needs: ['config', 'viewport', 'application']
queryParams: ['test']
test: null
...
...
但是,当我访问http://localhost:3333/#/changepassword?test=foo 时正在转换为:http://localhost:3333/#/changepassword
[旧]
这是我的路线:
module.exports = App.Router.map ->
@resource 'index', path: '/', ->
@resource('account_sign_up', path: '/signup')
@resource('unsubscribe', path: '/unsubscribe')
@resource('change_password', path: '/changepassword/:test1/:test2')
有什么帮助吗?谢谢!
【问题讨论】:
-
您似乎想使用query parameters,但您在路由中声明了路径参数。这些具有非常不同的语义。您应该阅读查询参数以查看它们是否适用于您的用例。 (最大的区别是您无法在路由的
model挂钩中访问它们。) -
@GJK 但我不需要在我的路线中添加参数?谢谢
-
不,查询参数是在控制器上声明的,而不是在路由上。
-
@GJK 哦,好的。但是现在如果我访问
changepassword?test=foo,该站点会将我重定向到changepassword。可以吗? -
您的控制器上是否声明了
test查询参数? Ember 现在管理您的查询参数,它不会允许错误的查询参数留在 URL 中。
标签: javascript ember.js coffeescript