我正在按角度对项目进行延迟加载,而我对路线有问题:角度为6,这是错误消息:
core.js:1673错误错误:未捕获(承诺):错误:无法匹配任何路由。网址段:“ sedes” 错误:无法匹配任何路线。网址段:“ sedes”
这是代码: // ------------------------------组件
import { Component, OnInit } from '@angular/core';
import {AbstractControl, FormGroup, FormControl, Validators} from
'@angular/forms';
import {LoginService} from '../services/login.service';
import{Router, ActivatedRoute} from '@angular/router';
import { UserService } from '../services/user.service';
import {variablesGlobales} from '../services/variablesGlobales';
import { map } from 'rxjs/operators';
import {ResponseData} from '../../common/ResponseData'
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
public loading:boolean
Error=""
admin=false
role=""
loginForm: FormGroup;
constructor(private loginService: LoginService,
private router: Router,
private _activatedRoute: ActivatedRoute,
private userService: UserService,
public _variablesGlobales: variablesGlobales,
)
{
this.loading=false
this.loginForm = new FormGroup({
email: new FormControl(null, Validators.required),
password: new FormControl(null, Validators.required)
});
}
ngOnInit() {
}
isValid(controlName){
return this.loginForm.get(controlName).invalid &&
this.loginForm.get(controlName).touched;
}
login(){
this.loading=true
debugger
if (this.loginForm.valid) {
this.loginService.login(this.loginForm.value)
.subscribe(data => {
this.userService.setUserLoggedIn(data);
this.loginService.getUserName().subscribe((response:ResponseData) =>
{
debugger
//localStorage.setItem('username',
response.username);
localStorage.setItem('role',
JSON.stringify(response.role));
localStorage.setItem('empresa',
response.empresa);
localStorage.setItem('sedes',
JSON.stringify(response.sedes));
// this._variablesGlobales.username=
response.username
// this._variablesGlobales.role=
response.role
// this._variablesGlobales.empresa=
response.empresa
// this._variablesGlobales.sedes=
response.sedes
let role=
JSON.parse(localStorage.getItem('role'))
//JSON.parse(roleArray);
if (role[0] == "admin") {
this.router.navigate(['/sedes']);
}else{
this.router.navigate(['/dashboard']);
localStorage.setItem('sede',
JSON.stringify(response.sedes[0]));
}
});
},
error => {this.loading=false;
console.log(error.error.message)
this.Error = error.error.message
});
}
}
}
//-------------------------------routing
import { NgModule } from '@angular/core';
import { RouterModule, Routes, PreloadAllModules } from
'@angular/router';
import {LoginComponent} from './login/login.component'
const routes: Routes = [
{
path: 'dashboard',
loadChildren: './sedes/dashboard/dashboard.module#DashboardModule'
},
{
path: 'sedes',
loadChildren: './sedes/sedes.module#SedeModule'
},
];
//export const PrivateRouting = RouterModule.forChild(routes);
// @NgModule({
// imports: [RouterModule.forChild(routes)],
// exports: [RouterModule]
// })
// export class PrivateRouting { }
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class PrivateRouting { }
//-----------------------------------module
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { CommonModule } from '@angular/common';
import {PrivateRouting} from './private.routing'
import {HttpClientModule} from '@angular/common/http';
import {DeviceDetectorModule } from 'ngx-device-detector';
//import {BrowserAnimationsModule} from '@angular/platform-
browser/animations';
//import { BrowserModule } from '@angular/platform-browser';
import {MatButtonModule, MatCheckboxModule} from '@angular/material';
import {MatInputModule } from '@angular/material'
import {FormsModule, ReactiveFormsModule } from '@angular/forms';
import {NgbModule } from '@ng-bootstrap/ng-bootstrap';
import {MatDialogModule} from '@angular/material/dialog';
import {MatFormFieldModule} from '@angular/material/form-field';
import {MatSelectModule} from '@angular/material/select';
//services
import {LoginService} from './services/login.service';
import { UserService } from './services/user.service';
import {variablesGlobales} from './services/variablesGlobales';
import {ResponseData} from '../common/ResponseData'
//component
import {LoginComponent} from './login/login.component'
const routes: Routes = [
{ path: '', component: LoginComponent },
];
@NgModule({
imports: [
RouterModule.forChild(routes),
CommonModule,
PrivateRouting,
HttpClientModule,
DeviceDetectorModule,
//BrowserAnimationsModule,
//BrowserModule,
MatButtonModule,
MatCheckboxModule,
MatInputModule,
FormsModule,
ReactiveFormsModule,
NgbModule,
MatDialogModule,
MatFormFieldModule,
MatSelectModule
],
declarations: [LoginComponent],
providers:[LoginService, UserService, variablesGlobales],
bootstrap:[LoginComponent]
})
export class PrivateModule { }