2017-04-28 7 views
1

ng build -prodでアプリケーションをビルドするときにルーティングに問題があります。 router.configは、これらのルートをprod環境でのみ登録します。ang 4:ビルド後のルーティング動作--prod

エラー:未知(約束):エラー:いずれのルートにも一致しません。 URLセグメント: 'myvehicle'↵Error:いずれのルートにも一致しません。 URLセグメント:私は上記のコードの代わりに、次のコードを使用する場合、 'myvehicle'

車両routing.module.ts

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

import { ConfigService } from '../../core/services/config/config.service'; 
import { VehicleComponent } from './vehicle.component'; 

const vehicleRoutes: Routes = []; 

ConfigService.scope('vehicle').getConfig().map(vehicle => { 
    vehicleRoutes.push({ 
    path: vehicle['informations']['route'], 
    component: VehicleComponent, 
    }); 
}); 

@NgModule({ 
    imports: [RouterModule.forChild(vehicleRoutes)], 
    exports: [RouterModule], 
}) 
export class VehicleRoutingModule { } 

export const routedComponents = [VehicleComponent]; 

header.component.html

<a [routerLink]="[vehicleService.getRoute(vehicle.id)]">... 

ルーティング作品:

const vehicleRoutes: Routes = [ 
    { 
    path: "test-a", 
    component: VehicleComponent, 
    },{ 
    path: "test-b", 
    component: VehicleComponent, 
    } 
]; 

は、私はパス値をチェックし、それがにconsole.logと同様、両方の方法で同じです(V ehicleRoutes)がdev/prod環境に出力されます。

ps:パスは、バックオフィスで設定されたスラッグに基づいているため、httpリクエストによってロードされます。

+0

' ... ' - この' vehicleService'はどこにありますか? 'header.component'に挿入されましたか? –

+0

VehicleServiceはコアフォルダにあり、私のAppModuleによってインポートされたCoreModuleによって提供されています。角度スタイルガイドルールhttps://angular.io/styleguide#!#04-11 その後、私はサービスを注入しました私のヘッダーコンポーネントで:コンストラクタ(public vehicleService:VehicleService){} – Naimor

+0

ああ、ありがとう、おそらくplunkerを作成する –

答えて

0

ベースタグ内のindex.htmlファイル内のベースURLを入力してください

例:

<base href="https://www.w3schools.com/images/" target="_blank"> 
+0

は既にindex.htmlに設定されています。 – Naimor

関連する問題