2016-12-29 1 views
2

angular2를 사용하여 웹 사이트를 구축 했으므로 localhost에서 제대로 작동하지만 내 서버에 배포하면 모든 CSS와 js 링크가 손상된 것 같습니다.angular2의 라우팅이 작동하지 않음 라이브 서버에서 작동하지 않음

예 : localhost : 4200/home은 잘 작동하지만 ip : 4200/home은 css 및 js 파일의 경우 404를 제공합니다.

IP : 4200 자체는 집에 있지만, 입력 IP로 리디렉션 : 4200/집은 내가 이들에 대한 라우팅을 수정해야 생각 (404)

을 제공에도 다시로드에 404을 제공합니다.

import { ModuleWithProviders } from '@angular/core'; 
import { Routes, RouterModule } from '@angular/router'; 


import { HomeComponent } from './component/home.component'; 
import { RegisterComponent } from './component/register.component'; 
import { ProductComponent } from './component/product.component'; 

const appRoutes: Routes = [ 

    { 
    path: '', 
    redirectTo: '/home', 
    pathMatch: 'full' 
    }, 

    { 
    path: 'home', 
    component: HomeComponent 
    }, 
    { 
    path: 'register', 
    component: RegisterComponent 
    }, 
    { 
    path: 'product', 
    component: ProductComponent 
    } 


]; 

수출 CONST 라우팅 : 다음과 같이

내 라우터 TS 파일은 ModuleWithProviders = RouterModule.forRoot (appRoutes를);

및 app.module.ts은 다음과 같이이다 :

import { NavBar } from './component/nav-bar.component'; 
import { RegisterService } from './services/register.service'; 
import { HomeService } from './services/home.service'; 
import { ProductService } from './services/product.service'; 
import { ProductComponent } from './component/product.component'; 
import { NavBar1 } from './component/nav-bar1.component'; 
@NgModule({ 
    declarations: [ 
    AppComponent, 
    HomeComponent, 
    RegisterComponent, 
    NavBar, 
    ProductComponent, 
    NavBar1 

    ], 
    imports: [ 
    BrowserModule, 
    FormsModule, 
    HttpModule, 
    RouterModule.forRoot([ 
     { 
      path: 'register', 
      component: RegisterComponent 
     } 
     ]), 

    routing 
    ], 
    providers: [ 
RegisterService, 
HomeService, 
ProductService 
    ], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 
+0

아마도 http://stackoverflow.com/questions/31415052/angular-2-0-router-not-working-on-reloading-the-browser –

답변

0

스위치

providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}, ... 

HashLocationStrategy에 또는 index.html에 존재하지 않는 파일에 대한 요청을 다시 (HTML5 pushState를 지원하도록 서버를 구성합니다.

+0

provice가 n을 제공하고 있습니다. ode_modules/@ angular/core/index " '내 보낸 멤버'provice '가 없습니다. . 및 심지어 내가 그것을 제공하여 시도 : 을하고는/같은 오류를 node_modules을 제공/코어/인덱스 "각 @ '제공 – kirti

+0

죄송합니다, 그 오타의'더 수출 멤버가 없다 '-해야을' –

+0

을 provide' 나는 aswel 제공하지만 여전히 동일한 오류 node_modules/@ 각도/코어/인덱스를 제공하려고 시도했다 "내 보내진 회원 '제공',이 모든 모듈을 설치해야합니까 – kirti

관련 문제