Angular 角度:布线不';我不能正确地显示我的组件
我的应用程序模块.ts:Angular 角度:布线不';我不能正确地显示我的组件,angular,Angular,我的应用程序模块.ts: import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { LoginComponent } from './login/login/login.component'; import { AppRoutingMod
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { LoginComponent } from './login/login/login.component';
import { AppRoutingModule } from './app-routing.module';
@NgModule({
declarations: [
AppComponent,
LoginComponent
],
imports: [
BrowserModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule, Routes } from '@angular/router';
import { LoginComponent } from './login/login/login.component';
export const appRoutes: Routes = [
{ path: '', component: LoginComponent},
{
path: 'ok',
component: LoginComponent,
},
// otherwise redirect to home
{
path: '**',
component: LoginComponent
}
];
@NgModule({
imports: [
RouterModule.forRoot(appRoutes),
],
exports:[
RouterModule
]
})
export class AppRoutingModule { }
我的应用程序路由。模块:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { LoginComponent } from './login/login/login.component';
import { AppRoutingModule } from './app-routing.module';
@NgModule({
declarations: [
AppComponent,
LoginComponent
],
imports: [
BrowserModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule, Routes } from '@angular/router';
import { LoginComponent } from './login/login/login.component';
export const appRoutes: Routes = [
{ path: '', component: LoginComponent},
{
path: 'ok',
component: LoginComponent,
},
// otherwise redirect to home
{
path: '**',
component: LoginComponent
}
];
@NgModule({
imports: [
RouterModule.forRoot(appRoutes),
],
exports:[
RouterModule
]
})
export class AppRoutingModule { }
我想将我的登录组件显示为主页,无论我选择什么路径,都会重定向到我的登录组件。我尝试将我的logincomponent
放入app.module.ts的引导程序中,但它给了我一个错误
我的登录组件是一个简单的
登录工具
您必须按如下方式配置路由
imports: [
RouterModule.forRoot([
{ path: '', component: LoginViewComponent },
{ path: 'ok', component: LoginViewComponent },
{ path: '**', redirectTo: 'login' }
])
]
修改您的
路由
添加重定向
路由和路径匹配
属性,告诉路由器如何将URL与路由路径匹配
export const appRoutes: Routes = [
{ path: '', redirectTo: '/ok', pathMatch: 'full' },
{
path: 'ok',
component: LoginComponent,
},
// otherwise redirect to home
{
path: '**',
component: LoginComponent
}
];
错误是什么?当我尝试将logincomponent作为引导时,错误是:选择器“app login”与任何元素都不匹配。我希望能够将我的logincomponent显示为我的主页以及指向该组件的任何其他路径。例如localhost:4000->login component、localhost:4000/qpownqwo->login component等。请单击答案左侧对您帮助最大的复选标记,结束您的问题