将hashlocation策略设置为true加载主模块角度2时出错

时间:2016-10-10 15:10:31

标签: angular angular2-routing

错误并没有解释太多,但我会写出来

  

错误:AppModule< @http://*******.********.com/app/main.js:73:17       
@http://*******.********.com/app/main.js:65:18       
@http://*******.********.com/app/main.js:1:1       
@http://*******.********.com/app/main.js:1:1       
ZoneDelegate.prototype.invoke@http://*******.********.com/node_modules/zone.js/dist/zone.js:203:19       
Zone.prototype.run@http://*******.********.com/node_modules/zone.js/dist/zone.js:96:24       
scheduleResolveOrReject /< @http://*******.********.com/node_modules/zone.js/dist/zone.js:462:52       
ZoneDelegate.prototype.invokeTask@http://*******.********.com/node_modules/zone.js/dist/zone.js:236:23       
Zone.prototype.runTask@http://*******.********.com/node_modules/zone.js/dist/zone.js:136:28       
drainMicroTaskQueue @ HTTP://*******.********.com/node_modules/zone.js/dist/zone.js:368:25       
ZoneTask/this.invoke@http://*******.********.com/node_modules/zone.js/dist/zone.js:308:25       

      评估http://*******.********.com/app/main.js       
加载http://*******.********.com/app/main.js

时出错

并在main.ts文件的第73行我有这一行

更新

Main.ts

import { NgModule }      from '@angular/core';
import { HttpModule } from '@angular/http';
import { BrowserModule } from '@angular/platform-browser';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { FormsModule }    from '@angular/forms';
import { RouterModule }   from '@angular/router';
import { APP_ROUTER_PROVIDERS } from './app.routes'
import {
     LocationStrategy,
     HashLocationStrategy
} from '@angular/common'
import { AppComponent } from './app.component'
import { Component1 } from './components/component1.component' 
import { Component2 } from './components/component2.component' 
import { Component3 } from './components/component3.component' 
import { Component4 } from './components/component4.component'
import { Component5 } from './components/component5.component'

@NgModule({
  imports:      [ BrowserModule,
                 FormsModule,
                 HttpModule,
                 RouterModule.forRoot(APP_ROUTER_PROVIDERS,{useHash:true})
               ],
  declarations: [Component1,
                 Component2
                 Component3
                 Component4
                 Component5
                 AppComponent
                 ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

platformBrowserDynamic().bootstrapModule(AppModule);

APP_ROUTER_PROVIDERS来自导入,它是Routes

的数组

app.routes.ts

import { Routes }  from '@angular/router';

import { Component1 } from './components/component1.component'
import { Component2 } from './components/component2.component'
import { Component3 } from './components/component3.component'
import { Component4 } from './components/component4.component'
import { Component5 } from './components/component5.component'
import { Login } from './components/login/login.component'

const routes: Routes = [
        {
        path:'',
        redirectTo: '/login',
        pathMatch: 'full'
        },
        {
        path: 'component1',
        component: Component1
        },
        {
        path: 'component2',
        component: Component2
        },
        {
        path:'component3',
        component:Component3
        },
        {
        path:'component4'
        component:Component4,
        },
        {
        path:'component5',
        component:Component5
        },
        {
        path:'login',
        component:Login
        }
  ];


  export const APP_ROUTER_PROVIDERS = routes

如果我用npm启动应用程序启动一切正常,但如果我在应用程序服务器上部署相同的应用程序,我会得到上面的错误,我做错了什么?我感觉路线被严重宣布。

0 个答案:

没有答案