2016-02-24 39 views
1

我想在前面安裝Angularjs 2風帆js應用程序。 我想使用angularJS系統路由和沒有風帆JS系統。AngularJS 2路線與風帆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 { 

} 

如果我刪除在配置/ routes.js的路線,這是行不通的。 我嘗試禁用config.blueprint.js中的一些選項,但沒有什麼好處。

我想要使用Angular路線有一個SPA,不要重新加載頁面。

謝謝。

回答

1

實際上,在嘗試直接訪問路由而不在服務器上進行配置時,出現錯誤是很正常的。事實上,當使用路由時,Angular2沒有任何與服務器的交互,所以路由的實際地址正在更新(並且沒有#/ hashbang方法)。該路徑在服務器上不存在。如果你加載HTML入口點文件,一切都會正常工作。唯一的問題是,當您嘗試直接從其路徑訪問路線時...

默認情況下,Angular2使用HTML5歷史記錄。如果您不想遇到此問題,則需要更新服務器以便爲您定義的每個路徑路徑提供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} 
]); 

在這種情況下,當您刷新頁面或直接訪問該頁面時,將再次顯示(但你的地址將有一個#)。

此鏈接可以幫助你還有:

希望它可以幫助你, 蒂埃裏

0

我必須回到 「/」 在配置/路由的所有路由.js並讓角度顯示其他視圖。