2016-09-24 14 views
3

私は角2を初めて使用しています。ルーティングに関する質問があります。私はapp.routingファイルを持っていますが、私は1つのパスしか必要としません。角2空のコンポーネントのルーティング

{path: 'signup', component: SignupComponent} 

しかし、私はこのコードを実行する場合、私はエラーを取得する:

Error: Uncaught (in promise): Error: Cannot match any routes: '' 

だから、私はちょうど私が望んでいたまさに同じように動作し「」パス、上の空のコンポーネントを使用することにしました。

ルーティングファイル:

import {Routes, RouterModule} from '@angular/router'; 
import {SignupComponent} from "./signup/signup.component"; 
import {EmptyComponent} from "./empty/empty.component"; 

const appRoutes:Routes = [ 
    {path: '', component: EmptyComponent}, 
    {path: 'signup', component: SignupComponent} 
]; 

export const appRoutingProviders = []; 

export const routing = RouterModule.forRoot(appRoutes); 

ルータ-コンセントを使用してファイル:

<header> 
    <div class="btn-wrapper"> 
     <button class="btn-sign-up btn-fancy" routerLink="/signup">Sign Up</button> 
     <button class="btn-sign-in btn-ghost btn-fancy">Sign In</button> 
    </div> 
    <i class="material-icons more">keyboard_arrow_down</i> 
    <router-outlet></router-outlet> 
    <div class="overlay" *ngIf="overlay" (click)="close()"></div> 
    <div class="tinted"></div> 
</header> 

私はちょうど 'サインアップ' パス上のルータはルートだけSignupComponentをすることを望みます。これを行い、空のコンポーネントの使用を排除する別の方法がありますか?この質問がうまく書かれていないのは残念ですが、私はStackOverflowの新機能です。

const appRoutes:Routes = [ 
    {path: '', redirectTo: 'signup', pathMatch: 'full'}, 
    {path: 'signup', component: SignupComponent} 
]; 

それとも、あなたがsignupに移動するまでルータのコンセントが空になりたい場合は、完全に空4を残す:

答えて

4

ちょうどあなたの空のルートがサインアップルートにリダイレクトします

const appRoutes:Routes = [ 
    {path: '', children: []}, 
    {path: 'signup', component: SignupComponent} 
]; 
+0

あなたの答えをありがとう!しかし、私はパス上にルーティングされるものは望まない。 SignupComponentは 'signup'にしか表示されません。 –

+0

もう一度おねがいしますが、このエラーが表示されます。ルート ''の設定が無効です:コンポーネントまたはリダイレクト先または子またはloadChildrenのいずれかを指定する必要があります –

+0

本当ですか?これは以前のベータ版では動作しましたが、もう動作しません。申し訳ありません。どの角度の角度を使用していますか? 2.0.0最終? – nickspoon

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

import { DemoComponent } from './demo.component'; 

const demoRoutes: Routes = [ 
    { path: '', component: DemoComponent } 
]; 

export const demoRouting: ModuleWithProviders = RouterModule.forChild(demoRoutes); 
関連する問題