We have child routes definitions presented here, in which we use a guard to check if the user has accepted terms before using our service.
account/secret/secret.routes.ts:
import { Routes } from '@angular/router';
import { SecretFormComponent } from './secret-form.component';
import { SecretTermsComponent } from './secret-terms.component';
import { TermsGuard } from './services/terms-guard.service';
export const secretRoutes: Routes = [
{
path: '',
redirectTo: 'form'
},
{
path: 'form',
component: SecretFormComponent,
canActivate: [TermsGuard]
},
{ path: 'terms', component: SecretTermsComponent }
// otherwise redirect to form
{ path: '**', redirectTo: 'form' }
];
In our terms-guard, we have defined this code:
this.router.navigate(['/account/secret/terms']);
return false;
Is there a way to redirect using relative route navigation from within a "routing group"? Because defining an absolute path may be break if one day our account website dashboard is renamed to anything else like my-account for example. We want our secret module to be reusable.
I'd like to be able to navigate to ['./terms']
in my guard but it doesn't work, just like the guard doesn't know "from where" to start relative navigation.