【问题标题】:EmberJS: Change path to access a routeEmberJS:更改路径以访问路由
【发布时间】:2014-05-07 20:03:29
【问题描述】:

我为我的应用程序定义了一个Router.map。我正在使用 EmberJS AppKit 架构。 https://github.com/stefanpenner/ember-app-kit

我想使用以下路径访问我的页面“个人资料”: http://localhost:8000/#/profile

但是,我的路由名称与这条路径不同,因为它叫user-profile,所以我这样做了:

router.js

var Router = Ember.Router.extend();

Router.map(function () {
    this.resource('user-profile', { path: 'profile'}, function() {
        //Some other things...
    });
});

export default Router;

user-profile.js

export default Ember.Route.extend({
    model: function () {
        return this.store.find('user-profile');
    }
});

当我启动我的应用程序时,Ember 告诉我 profile 路由不存在,即使我定义了路径:

Uncaught Error: Assertion Failed: Error: Assertion Failed: The URL '/profile' did not match any routes in your application

你知道我的代码现在有什么问题吗?

谢谢

【问题讨论】:

    标签: javascript model-view-controller ember.js ember-router


    【解决方案1】:

    我不使用 ember appkit,但也许可以尝试使用下划线,即“user_profile”并重命名您的文件。只是在黑暗中拍摄。

    【讨论】:

      【解决方案2】:

      我不得不猜测这是您设计路由器和命名空间的方式。

      典型的准系统 Ember 应用需要:

      window.App = Ember.Application.create({
        LOG_TRANSITIONS: true,
        LOG_TRANSITIONS_INTERNAL: true
      });
      
      App.Router.map(function () {
        this.resource('user-profile', { path: 'profile'}, function() {
        //Some other things...
      });
      

      在您的示例中,您的路由器不在 App 命名空间中,也不在任何您的根对象的名称中(它不必是“App”)。如果还有其他我在这里看不到的因素,我会尝试一下,或者发布更多代码。

      此外,通常您会将路线命名为 userProfile。虽然我不认为 dasherized 名称有问题,但它不遵循 Ember 命名约定。

      希望这会有所帮助。

      【讨论】:

      • 我正在使用不需要此命名空间的 Ember AppKit。
      • 我明白了,更多的代码仍然会有所帮助。您是否定义了实际路线? App.UserProfileRoute = Ember.Route.extend({})?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多