NavLinkComponentでアクセス可能ですが、HomeLinkを使用してRouterLinkを使用することはできません。私は、異なるテンプレートビューで2(ng g component
から生成)と同じコンポーネントコードを持っています。 app.module.tsのコードはここにRouterLinkはNavbarComponentで動作しますがHomeComponentでは動作しません
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { Router } from '@angular/router';
import { RoutingModule } from './routing.module';
import { AppComponent } from './app.component';
import { NavbarComponent } from './navbar/navbar.component';
import { HomeComponent } from './home/home.component';
@NgModule({
declarations: [
AppComponent,
NavbarComponent,
HomeComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
RoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
であると私RoutingModule
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
const router = [
{ path: '', component: HomeComponent},
{ path: 'about', component: AboutComponent}
];
@NgModule({
imports: [ RouterModule.forRoot(router) ],
exports: [ RouterModule ]
})
export class RoutingModule { }
は、それは彼らと何か問題ですか?それともコンポーネントそのものなのでしょうか?ここにHomeComponentのコンポーネントコードがあり、NavbarComponentと全く同じですが、異なる名前です。
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
編集:これはAngular2レンダリングです。
<a _ngcontent-myo-3="" class="btn btn-primary btn-xl" routerlink="about" ng-reflect-router-link="about" ng-reflect-href="/about" href="/about">Find Out More</a>
これは私がバックエンドに持っているものです。
<a routerLink="about" class="btn btn-primary btn-xl">Find Out More</a>
そして、これは、リンク(ないクリッカブル)ではありません
'AppComponent'は' NavbarComponent'ですか?そうでなければ、あなたの 'routing'ファイルにはありません。 –
「HomeComponentを使用してRouterLinkを使用することはできません」とはどういう意味ですか?あなたは何かエラーがありますか? – mickdev
「Find Out More」はリンクとして認識されません。 'NavbarComponent'はナビゲーションバーです。レンダリングするサイトではないので、' RoutingModel'へのアクセス権を与えませんでした。 'NavbarComponent'は' RoutingModel'を使用しますが、 'RoutingModel'は' NavbarComponent'を使用しません。それは間違った論理ですか?私は新しい角度になっていますが、 'RouterLink'を使うために' HomeComponent'を追加するまでうまく動作します。 –