问题
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