路由器在单页面应用程序中的作用是什么

fla*_*ash 6 ember.js single-page-application

我是Ember-js的新手,我最近浏览了一些博客文章,还看到了Tom Dale介绍的Ember-js视频.

总结一下,他们说路由器Api是新推出的,它是Ember-js发生的最好的事情,路由器Api用于管理应用程序的状态,每个状态都用URL标识,现在用于单页应用程序,其中我们只使用一个URL,路由器的作用是什么,只有一个路由条目映射到'/'(索引)?如果是,那么我们失去了路由器api提供的优势吗?

Mik*_*tti 4

现在,对于我们仅使用一个 URL 的单页应用程序,路由器的作用是什么?是否只有一个映射到“/”(索引)的路由条目?

通常,单页应用程序仍会使用 url。例如,使用 Gmail 时观察 url 变化。因此,在这种情况下,单页应用程序意味着浏览器不会在 url 更改时获取新页面。与 gmail 一样,典型的 ember 单页应用程序将在用户导航到应用程序的各个部分时更改 url。ember 路由器会自动处理这个问题。

如果是的话,那么我们就失去了 Router api 提供的优势,对吗?

如果您决定不使用该 url,并且确实希望它始终保留“/”,您仍然可以使用路由器。只需将路由器的位置类型设置为“无”

请参阅http://emberjs.com/guides/routing/specifying-the-location-api/

我理解这里的路由意味着管理状态,但是在任何时候用户都可以处于一组状态,例如gmail,用户将处于登录状态和撰写状态,如何管理同时存在的多个状态?

这肯定是真的。ember 路由器基本上是一个状态图,其中路由(叶节点)嵌套在一定数量的资源下。因此,以 gmail 为例,只有登录用户才能处于撰写状态。

GMail 网址:https://mail.google.com/mail/u/0/?shva=1#inbox

// Gmail Routes:
* /mail - the mail application
* /u/0 - connected account index 0 for the current user
* ?shva=1 - http://stackoverflow.com/questions/1692968/what-is-shva-in-gmails-url
* inbox - folder name
Run Code Online (Sandbox Code Playgroud)

灰烬邮件版本:https://mail.ember.com/mail/u/0/inbox

// EmberMail Routes
this.resource('mail', { path: '/mail' }, function() {
  this.resource('currentUser', { path: '/u' }, function() {
    this.resource('account', { path: '/:account_id' }, function() {
      this.route('folder', { path: '/:folder_id' });
    });
  });
});
Run Code Online (Sandbox Code Playgroud)

您能给我指出一个广泛使用路由的示例应用程序吗?

我所知道的最好的例子就是话语。查看以下示例,了解大型 ember 应用程序如何使用 ember 路由器: