Angular JS 2 route with sails js



我正在尝试设置一个前面有Angularjs 2的sails js应用程序。我想使用angularJS系统路由,而不是sails js系统。

如何禁用帆路线并让角度控制它们?这是我的app.component.ts,我在其中声明路由/帐户

import {View, Component} from 'angular2/core';
import {RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router';
import {AccountComponent}   from './account.component';
@Component({
    selector: 'my-app',
    template: `<router-outlet></router-outlet>`,
    directives: [ROUTER_DIRECTIVES]
})
@RouteConfig ([
    {path: '/account', name: 'Account', component: AccountComponent}
])

export class AppComponent {
}

如果我在配置/路由.js中删除路由,这不起作用。我尝试禁用config.blueprint中的某些选项.js但没有什么好东西。

我想使用 Angular 路由来拥有 SPA 并且不重新加载页面。

谢谢。

事实上,在没有服务器上配置的情况下尝试直接访问路由时出现错误是正常的。事实上,路由的实际地址是由 Angular2 更新的(并且没有 #/hashbang 方法),在使用路由时与服务器没有任何交互。服务器上不存在该路径。如果加载 HTML 入口点文件,一切正常。唯一的问题是当您尝试从其路径直接访问路由时......

默认情况下,HTML5历史记录由Angular2使用。如果不希望遇到此问题,则需要更新服务器以提供您定义的每个路由路径的index.html文件。

如果要切换到 HashBang 方法,则需要使用以下配置:

import {bootstrap} from 'angular2/platform/browser';
import {provide} from 'angular2/core';
import {ROUTER_PROVIDERS} from 'angular2/router';
import {LocationStrategy, Location, HashLocationStrategy } from 'angular2/router'; 
import {MyApp} from './myapp';
bootstrap(MyApp, [
  ROUTER_PROVIDERS,
  provide(LocationStrategy, {useClass: HashLocationStrategy}
]);

在这种情况下,当您刷新页面或直接访问页面时,它将再次显示(但您的地址中将有一个#)。

此链接也可以为您提供帮助:

  • Angular 2:通过浏览器刷新时发生404错误

希望对您有所帮助,蒂埃里

我必须为配置/路由中的所有路由返回"/".js并让角度显示其他视图。

最新更新