Ember js - Cannot generate URL with dynamic segments using urlFor method

不打扰是莪最后的温柔 提交于 2020-02-05 14:55:27

问题


I am able to generate a URL using urlFor() when I’m in the route /1/1/orders. but I’m unable to generate a URL in the application route.

So this code is not working:

var routeName = "scope.purchase.invoice";
var dynamicSegments = { scopeId: 1, scopeData: 2, invoiceId: 3, pageSize: 20, pageIndex: 1 };
var url = this.router.urlFor(routeName, 1, 2, 3, 10, 1);
console.log("inside generated url", url);

For this router.js:

this.route("scope", { path: '/:scopeId/:scopeData' }, function(){
  this.route("purchase", function(){
    this.route("invoice", { path: '/:invoiceId/:pageIndex/:pageSize' });
  })
});

here is the reference ember-twiddle


回答1:


Your problem is that urlFor() takes the models / dynamic segments as individual, ordered params, not a object with keys and values..

So do this:

const url = this.router.urlFor(routeName, dynamicSegments.scopeId, dynamicSegments.scropeData, dynamicSegments.invoiceId, dynamicSegments.pageSize, dynamicSegments.pageIndex);


来源:https://stackoverflow.com/questions/59951480/ember-js-cannot-generate-url-with-dynamic-segments-using-urlfor-method

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