Angular 7 - Изменить базовый URL-адрес отдельного компонента внутри маршрутов - PullRequest
0 голосов
/ 18 июня 2020

Все мои маршруты go к версии множественного числа builder-jobs/, но я хотел бы знать, могу ли я изменить один на go на builder-job/:id, но оставив остальные как builder-jobs

Это мой текущий файл модуля - builder-jobs.module.ts:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Routes, RouterModule } from '@angular/router';
import { BuilderJobModule } from '@/modules/builder-jobs/builder-job.module';
import {
    QualityInspectionAddComponent,
    QualityInspectionViewComponent,
    SafetyInspectionAddComponent,
    SafetyInspectionViewComponent,
} from '@/modules/jobs/job.module';

import { AuthGuard } from '@/guards/auth/auth.guard';
import { Role } from '@/models/role';

import { BuilderJobsCalendarComponent } from './builder-jobs-calendar/builder-jobs-calendar.component';
import { BuilderJobsViewComponent } from './builder-jobs-view/builder-jobs-view.component';
import { BuilderJobsAddComponent } from './builder-jobs-add/builder-jobs-add.component';
import { BuilderJobComponent } from './builder-job/builder-job.component';

export const routes: Routes = [
    {
        path: 'view',
        component: BuilderJobsViewComponent,
        canActivate: [AuthGuard],
        data: { roles: [Role.Admin, Role.Supervisor, Role.CrewLeader] }
    },
    {
        path: 'add',
        component: BuilderJobsAddComponent,
        canActivate: [AuthGuard],
        data: { roles: [Role.Admin] }
    },
    {
        path: 'calendar',
        component: BuilderJobsCalendarComponent,
        canActivate: [AuthGuard],
        data: { roles: [Role.Admin, Role.Supervisor] }
    },
    {
        path: ':id',
        canActivate: [AuthGuard],
        component: BuilderJobComponent,
        data: { roles: [Role.Admin, Role.Supervisor, Role.CrewLeader] }
    },
    {
        path: ':id/safety-inspection/:checklist_id',
        canActivate: [AuthGuard],
        component: SafetyInspectionViewComponent
    },
    {
        path: ':id/safety-inspection-add',
        canActivate: [AuthGuard],
        component: SafetyInspectionAddComponent
    },
    {
        path: ':id/quality-inspection/:checklist_id',
        canActivate: [AuthGuard],
        component: QualityInspectionViewComponent
    },
    {
        path: ':id/quality-inspection-add',
        canActivate: [AuthGuard],
        component: QualityInspectionAddComponent
    },
    {
        path: '',
        redirectTo: '/builder-jobs/view',
        pathMatch: 'full'
    },
    {
        path: '**',
        redirectTo: '/builder-jobs/view',
        pathMatch: 'full'
    }
];

@NgModule({
    declarations: [
        BuilderJobsCalendarComponent,
        BuilderJobsViewComponent,
        BuilderJobsAddComponent,
        BuilderJobComponent,
    ],
    imports: [
        CommonModule,
        BuilderJobModule,
        RouterModule.forChild(routes),
    ],
})
export class BuilderJobsModule { }

Я хочу изменить указанный c маршрут:

{
    path: ':id',
    canActivate: [AuthGuard],
    component: BuilderJobComponent,
    data: { roles: [Role.Admin, Role.Supervisor, Role.CrewLeader] }
},

Я пробовал path: 'builder-job/:id', но это не так ' кажется, работает - идет на 404

вот мой app-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule, PreloadAllModules} from '@angular/router';
import { AuthGuard } from '@/guards/auth/auth.guard';

import { DashboardComponent } from '@/views/dashboard/dashboard.component';
import { PageNotFoundComponent } from '@/views/page-not-found/page-not-found.component';
import { LoginComponent } from '@/views/login/login.component';
import { PasswordResetComponent } from '@/views/password-reset/password-reset.component';
import { NewPasswordComponent } from '@/views/new-password/new-password.component';

import { Role } from '@/models/role';

const routes: Routes = [
    {
        path: 'incidents',
        canActivate: [AuthGuard],
        loadChildren: () => import('@/views/incidents/incidents.module').then(mod => mod.IncidentsModule)
    },
    {
        path: 'dashboard',
        canActivate: [AuthGuard],
        loadChildren: () => import('@/views/dashboard/dashboard.module').then(mod => mod.DashboardModule)
    },
    {
        path: 'builders',
        canActivate: [AuthGuard],
        loadChildren: () => import('@/views/builders/builders.module').then(mod => mod.BuildersModule),
    },
    {
        path: 'communities',
        canActivate: [AuthGuard],
        loadChildren: () => import('@/views/communities/communities.module').then(mod => mod.CommunitiesModule),
        data: { roles: [Role.Admin, Role.Supervisor, Role.CrewLeader] }
    },
    {
        path: 'reroof-jobs',
        loadChildren: () => import('@/views/reroof-jobs/reroof-jobs.module').then(mod => mod.ReroofJobsModule),
        canActivate: [AuthGuard],
        data: { roles: [Role.Admin] }
    },
    {
        path: 'builder-jobs',
        canActivate: [AuthGuard],
        loadChildren: () => import('@/views/builder-jobs/builder-jobs.module').then(mod => mod.BuilderJobsModule),
        data: { roles: [Role.Admin, Role.Supervisor, Role.CrewLeader] }
    },
    {
        path: 'repair-jobs',
        canActivate: [AuthGuard],
        loadChildren: () => import('@/views/repair-jobs/repair-jobs.module').then(mod => mod.RepairJobsModule),
        data: { roles: [Role.Admin, Role.Supervisor, Role.CrewLeader] }
    },
    {
        path: 'warranty-jobs',
        canActivate: [AuthGuard],
        loadChildren: () => import('@/views/warranty-jobs/warranty-jobs.module').then(mod => mod.WarrantyJobsModule),
        data: { roles: [Role.Admin, Role.Supervisor, Role.CrewLeader] }
    },
    {
        path: 'employees',
        canActivate: [AuthGuard],
        loadChildren: () => import('@/views/employees/employees.module').then(mod => mod.EmployeesModule),
        data: { roles: [Role.Admin, Role.Supervisor] }
    },
    {
        path: 'contacts',
        canActivate: [AuthGuard],
        loadChildren: () => import('@/views/contacts/contacts.module').then(mod => mod.ContactsModule),
        data: { roles: [Role.Admin, Role.Supervisor] }
    },
    {
        path: 'users',
        canActivate: [AuthGuard],
        loadChildren: () => import('@/views/users/users.module').then(mod => mod.UsersModule),
        data: { roles: [Role.Admin, Role.Supervisor] }
    },
    {
        path: 'time-entries',
        canActivate: [AuthGuard],
        loadChildren: () => import('@/views/time/time.module').then(mod => mod.TimeModule),
        data: { roles: [Role.Admin, Role.Supervisor, Role.CrewLeader] }
    },
    {
        path: 'alerts',
        canActivate: [AuthGuard],
        loadChildren: () => import('@/views/alerts/alerts.module').then(mod => mod.AlertsModule),
        data: { roles: [Role.Admin, Role.Supervisor, Role.CrewLeader] }
    },
    {
        path: 'login',
        component: LoginComponent
    },
    {
        path: 'password-reset',
        component: PasswordResetComponent
    },
    {
        path: 'new-password',
        component: NewPasswordComponent
        },
    {
        path: '',
        redirectTo: '/dashboard',
        pathMatch: 'full'
    },
    {
        path: '',
        component: DashboardComponent,
        canActivate: [AuthGuard],
        children: [
            {
                path: '',
                canActivateChild: [AuthGuard],
                children: []
            }
        ]
    },
    {
        path: '**',
        component: PageNotFoundComponent
    }
];

@NgModule({
  imports: [
    RouterModule.forRoot( routes )
  ],
  exports: [
    RouterModule
  ],
})
export class AppRoutingModule { }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...