在路线urlFor()中,我可以使用/1/1/orders生成URL。但我无法在应用程序路由中生成URL。

因此此代码不起作用:

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);


为此router.js

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


这是参考文献ember-twiddle

最佳答案

您的问题是urlFor() takes the models / dynamic segments as individual, ordered params, not a object with keys and values.

这样做:

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

08-28 15:10