Api 身份验证后出现角度2错误-找不到要加载的主出口
身份验证后控制台中出现错误。重新加载页面后,CreateChartComponent页面开始工作。验证过程中刚刚发生错误Api 身份验证后出现角度2错误-找不到要加载的主出口,api,angular,authentication,angular2-routing,Api,Angular,Authentication,Angular2 Routing,身份验证后控制台中出现错误。重新加载页面后,CreateChartComponent页面开始工作。验证过程中刚刚发生错误 Uncaught (in promise): Error: Cannot find primary outlet to load 'CreateChartComponent' 这是登录功能 login(event, username, password): void { event.preventDefault(); this.authService.login(usern
Uncaught (in promise): Error: Cannot find primary outlet to load 'CreateChartComponent'
这是登录功能
login(event, username, password): void {
event.preventDefault();
this.authService.login(username, password).subscribe(
res => {
this.router.navigate(['drawing']);
},
err => {
// todo: handle error with a lable
console.log(err);
if (err.ok === false) {
this.errorMessage = 'Error logging in.';
}
});
}
}
传统信息:
我发送清晰模式的代码,我得到相同的问题。
这是路由器代码:
// Import our dependencies
import { Routes } from '@angular/router';
import { AppComponent } from './app.component';
import { LoginComponent } from './home/login/login.component';
import { CreateChartComponent } from './home/drawing/create-chart.component';
import { AuthGuard } from './auth.guard';
// Define which component should be loaded based on the current URL
export const routes: Routes = [
{ path: '', component: CreateChartComponent, pathMatch: 'full', canActivate: [AuthGuard] },
{ path: 'login', component: LoginComponent },
{ path: 'drawing', component: CreateChartComponent, canActivate: [AuthGuard] },
];
以及它的create-chart.component.ts
import {
Component,
OnInit,
} from '@angular/core';
@Component({
selector: 'np-chart-create',
templateUrl: './create-chart.component.html',
styleUrls: ['./create-chart.component.css']
})
export class CreateChartComponent implements OnInit {
ngOnInit() {
}
}
共享您的CreateChartComponent、路由器文件和App.component.ts的代码,其中定义了您的路由器出口。您的路由怎么了,似乎有点奇怪。我看到在访问
CreateChartComponent
之前需要登录,所以路径'
不应该引用登录组件吗?