Я работаю с угловой структурой nativescript 4+. я сделал вход и регистрацию компонента. но сейчас у меня проблемы с основным компонентом.
дерево вот такое
app
{
main,
login,
register
}
тогда. main имеет canActivate
охранника. если пользователь еще не авторизовался. пользователь должен сначала войти в систему или создать учетную запись.
проблема заключается в основном компоненте, который имеет много дочерних элементов.
моя основная маршрутизация такая.
import { NgModule } from '@angular/core';
import { Routes } from '@angular/router';
import { NativeScriptRouterModule } from 'nativescript-angular/router';
import { MainComponent } from './main.component';
import { ProfileComponent } from './home/profile.component';
import { AddStoreComponent } from './home/add-store/add-store.component';
import { EditProfileComponent } from './home/edit-profile/edit-profile.component';
import { StoreComponent } from './store/store.component';
import { EditStoreProfileComponent } from './store/edit-store-profile/edit-store-profile.component';
import { GoodsComponent } from './store/goods/goods.component';
import { AddGoodsComponent } from './store/goods/add-goods/add-goods.component';
import { EditGoodsComponent } from './store/goods/edit-goods/edit-goods.component';
import { StaffComponent } from './store/staff/staff.component';
import { AddStaffComponent } from './store/staff/add-staff/add-staff.component';
import { EditStaffComponent } from './store/staff/edit-staff/edit-staff.component';
import { StoreProfileComponent } from './store/store-profile/store-profile.component';
import { TransactionComponent } from './store/transaction/transaction.component';
import { AddTransactionComponent } from './store/transaction/add-transaction/add-transaction.component';
const routes: Routes = [
{
path: '',
component: MainComponent,
children: [
{
path: '',
redirectTo: '/profile',
pathMatch: 'prefix'
},
{ path: 'profile', component: ProfileComponent },
{ path: 'edit-profile', component: EditProfileComponent },
{ path: 'add-store', component: AddStoreComponent },
{
path: 'store:id',
component: StoreComponent,
children: [
{
path: '',
redirectTo: '/store-profile',
pathMatch: 'full'
},
{ path: 'store-profile', component: StoreProfileComponent },
{
path: 'edit-store-profile',
component: EditStoreProfileComponent
},
{ path: 'goods', component: GoodsComponent },
{ path: 'edit-goods', component: EditGoodsComponent },
{ path: 'add-goods', component: AddGoodsComponent },
{ path: 'staff', component: StaffComponent },
{ path: 'edit-staff', component: EditStaffComponent },
{ path: 'add-staff', component: AddStaffComponent },
{ path: 'transaction', component: TransactionComponent },
{
path: 'add-transaction',
component: AddTransactionComponent
}
]
}
]
}
];
@NgModule({
imports: [NativeScriptRouterModule.forChild(routes)],
exports: [NativeScriptRouterModule]
})
export class MainRoutingModule {}
мой mainRouting хорош или отстой?
моя цель: когда я иду к main component
, я автоматически иду к profile component
но мой код не работает.
я пробовал изменить path : 'profile' to path : ''
. оно работает. но мне нужно позвонить '/profile' route
и я хочу, чтобы route ''
был моим корнем для route '/main'