我是angular 5的新手。我知道非常基本的管理员,请帮助我解决这个问题。我已经从https://github.com/akveo/nebular下载了ngx- routing.So,现在我想为它制作登录页面,当用户点击url.I时,登录页面将首先出现。我尝试过这个,但它不起作用,这是应用路由。模块
import { ExtraOptions, RouterModule, Routes } from '@angular/router';
import { NgModule } from '@angular/core';
import {
NbAuthComponent,
NbLoginComponent,
NbLogoutComponent,
NbRegisterComponent,
NbRequestPasswordComponent,
NbResetPasswordComponent,
} from '@nebular/auth';
import { LoginComponent } from './login/login.component';
const routes: Routes = [
{path : '' , component: LoginComponent},
{ path: 'pages', loadChildren: 'app/pages/pages.module#PagesModule' },
{
path: 'auth',
component: NbAuthComponent,
children: [
{
path: '',
component: NbLoginComponent,
},
{
path: 'login',
component: NbLoginComponent,
},
{
path: 'register',
component: NbRegisterComponent,
},
{
path: 'logout',
component: NbLogoutComponent,
},
{
path: 'request-password',
component: NbRequestPasswordComponent,
},
{
path: 'reset-password',
component: NbResetPasswordComponent,
},
],
},
{ path: '', redirectTo: 'login', pathMatch: 'full' },
{ path: '**', redirectTo: 'pages' },
];
const config: ExtraOptions = {
useHash: true,
};
@NgModule({
imports: [RouterModule.forRoot(routes, config)],
exports: [RouterModule],
})
export class AppRoutingModule {
}
这是page-routing.module.ts
import { RouterModule, Routes } from '@angular/router';
import { NgModule } from '@angular/core';
import { PagesComponent } from './pages.component';
import { DashboardComponent } from './dashboard/dashboard.component';
import { ManageComponent } from './manage/manage.component';
import { UserComponent } from './user/user.component';
const routes: Routes = [{
// path: '/home',
path:'',
component: PagesComponent,
children: [{
path: 'dashboard',
component: DashboardComponent,
}, {
path: 'ui-features',
loadChildren: './ui-features/ui-features.module#UiFeaturesModule',
},
{
path: 'add-booking',
loadChildren: './add-booking/addbooking.module#AddbookingModule',
},{
path: 'components',
loadChildren: './components/components.module#ComponentsModule',
}, {
path: 'maps',
loadChildren: './maps/maps.module#MapsModule',
}, {
path: 'charts',
loadChildren: './charts/charts.module#ChartsModule',
}, {
path: 'editors',
loadChildren: './editors/editors.module#EditorsModule',
}, {
path: 'forms',
loadChildren: './forms/forms.module#FormsModule',
}, {
path: 'tables',
loadChildren: './tables/tables.module#TablesModule',
},
{
path: 'manage',
component: ManageComponent,
},
{
path: 'user',
component: UserComponent,
},{
path: '',
redirectTo: 'dashboard',
pathMatch: 'full',
}],
}];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class PagesRoutingModule {
}
发布于 2018-04-01 15:53:53
尝试更改app-routing.module.ts中的登录: redirectTo:‘auth/ redirectTo’
发布于 2018-05-31 16:20:51
嘿,把它改成这样
App-routing.module.ts
const routes: Routes = [
{ path: 'pages', loadChildren: 'app/pages/pages.module#PagesModule' },
{
path: '',
component: NbAuthComponent,
children: [
{
path: '',
component: NbLoginComponent,
},
{
path: 'login',
component: NbLoginComponent,
},
{
path: 'register',
component: NbRegisterComponent,
},
{
path: 'logout',
component: NbLogoutComponent,
},
{
path: 'request-password',
component: NbRequestPasswordComponent,
},
{
path: 'reset-password',
component: NbResetPasswordComponent,
},
],
},
{ path: '', redirectTo: 'pages', pathMatch: 'full' },
{ path: '**', redirectTo: 'pages' },
];
https://stackoverflow.com/questions/48579902
复制相似问题