Ember.js路由:url中的动态段错误

Ember.js Routes: Dynamic segments in url error

本文关键字:段错误 错误 动态 路由 js url Ember      更新时间:2023-09-26

我的路由器看起来像:

App.Router.map(function () {
    this.route('index', {path: '/'})
    this.resource('products', function () {
        this.route('all', {path: '/'});
        this.resource('products.edit', {path: '/edit/:id'}, function () {
            this.route('general');
            this.route('images');
            this.route('reviews');
        });
    });
    this.resource('category', function () {
        this.route('all', {path: '/'});
        this.resource('category.edit', {path: '/edit/:category_id'}, function () {
            this.route('general');
            this.route('images');
            this.route('products_of_category');
        });
    });
});

在导航菜单中,我有"添加/编辑Product"answers"添加/修改Category",它们链接到products.editcategory.edit路线。但当我渲染页面时,我得到一个错误,说:

TypeError: newHandlerInfo is undefined

当我去除嵌段:product_id:category_id时,它工作得很好。

以下是我的型号:

App.Product = Ember.Object.extend({
    id: null,
    productName: null,
    dateAdded: null,
    description: null,
    price: null,
    status: null,
    categories: [],
    categoryNames: []
});
App.Category = Ember.Object.extend({
    id: null,
    categoryName: null,
    dateAdded: null,
    description: null,
    children: [],
    parent: null,
    products: []
});

可能是您想要的路由器:

App.Router.map(function() {
  this.route('index', {path: '/'});
  this.resource('products', function() {
    this.route('all', {path: '/'});
    this.route('edit_general', {path: '/edit/:product_id/general'});
    this.route('edit_images', {path: '/edit/:product_id/images'});
    this.route('edit_reviews', {path: '/edit/:product_id/reviews'});
  });
  this.resource('category', function() {
    this.route('all', {path: '/'});
    this.route('edit_general', {path: '/edit/:category_id/general'});
    this.route('edit_images', {path: '/edit/:category_id/images'});
    this.route('edit_products', {path: '/edit/:category_id/products'});
  });
});