首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >EmberJS:更改路径以访问路由

EmberJS:更改路径以访问路由
EN

Stack Overflow用户
提问于 2014-05-07 20:03:29
回答 2查看 231关注 0票数 1

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

我想使用以下路径访问我的页面“配置文件”:http://localhost:8000/#/profile

但是,我的路径名与这个路径不同,因为它调用了user-profile,所以我这样做了:

router.js

代码语言:javascript
复制
var Router = Ember.Router.extend();

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

export default Router;

user-profile.js

代码语言:javascript
复制
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

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

谢谢

EN

回答 2

Stack Overflow用户

发布于 2014-05-18 01:58:36

我不使用ember,但可能尝试下划线,即'user_profile‘和重命名您的文件太。只是黑暗中的一枪。

票数 0
EN

Stack Overflow用户

发布于 2014-05-07 20:31:02

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

通常,一个简单的Ember应用程序需要:

代码语言:javascript
复制
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。虽然我不认为这个名称是一个问题,但它并不遵循Ember命名规则。

希望这能有所帮助。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23527299

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档