使用CLI进行角度路由

时间:2018-04-20 04:52:57

标签: angular routing command-line-interface

角度路由不起作用。它只适用于我输入index.html

我做的路由是否合适? 如果有人有与棱镜有关的例子,那么请发邮件给我saijalshakya1@gmail.com

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';   
import { AppComponent } from './app.component';
import { OurteamComponent } from './ourteam/ourteam.component';
import { AppRoutingModule } from './app-routing.module';

@NgModule({
  declarations: [
    AppComponent,
    OurteamComponent
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

应用-routing.module.ts

   import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';


import { AppComponent } from './app.component';
import { OurteamComponent } from './ourteam/ourteam.component';
import { AppRoutingModule } from './app-routing.module';

@NgModule({
  declarations: [
    AppComponent,
    OurteamComponent
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.html

<h1>saijal shakya</h1>

<router-outlet></router-outlet>

ourteam.component.html

<p>
  ourteam works!
</p>
<router-outlet></router-outlet>

的index.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Sxc</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您尚未在app.module.ts的导入中使用AppRoutingModule。 确保在那里是必需的。 另外,您的app.routing.module.ts与app.module.ts相同,这是不正确的。

使用app.routing.module.ts文件定义路线及其组件的映射。