ember.js - 路由器在单页应用中的作用是什么

标签 ember.js single-page-application

我是 Ember-js 的新手,我最近浏览了一些博客条目,还看到了 Tom dale 介绍 Ember-js 的视频。

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

最佳答案

now for a single page application where in we use only one URL, what is the role of the router, will there be only one routeing entry which is mapped to '/'(index)?



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

If yes, then we lose the advantage provided by the Router api right?



如果您决定不使用 url,并且真的希望它一直保持“/”,您仍然可以使用路由器。只需将路由器的位置类型设置为“无”

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

I understand that routing here means managing states, but at any point of time user can be in a set of states for instance take gmail the user would be in login state and compose state, how to manages multiple states existing together?



这肯定是真的。 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

EmberMail 版本: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' });
    });
  });
});

can you point me to a example application which uses routing extensively?



我所知道的最好的例子是话语。查看以下示例,了解大型 ember 应用程序如何使用 ember 路由器:
  • 话语 Application routes
  • 话语 Admin routes
  • 关于ember.js - 路由器在单页应用中的作用是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15472802/

    相关文章:

    javascript - Ember - 如何在 Controller 方法之后调用 View 方法

    javascript - Ember 扩展组件计算属性?

    if-statement - #if 语句抛出 TypeError : node is undefined

    javascript - 使用 SPA 且没有服务器端计算时,如何正确处理 404 HTTP 错误?

    angular - Azure Web 应用程序 Angular 5 + dotnet core 2.1 部署后刷新

    javascript - 在登录页面和仪表板之间 Split View的最佳方式 Routing Vue js for SPA

    Ember.js - 学习动态段、链接、嵌套路由

    javascript - 如何编译内联 HTMLBars 模板?

    javascript - AngularJS 单页应用程序架构

    javascript - 在没有 Entity Framework 的情况下使用 Breeze.js