Angolare route di default sempre precaricato

0

Domanda

Ho due percorsi :

  • home [ " ]
  • circa [ 'info' ]

Quando vado in /direttamente con il mio browser, ho notare 2 cose :

  • la mia casa modulo è precaricato (considerando che ho richiesto e /o circa)
  • l'URL è rewritted come questo : /about -> / -> /circa

app-di routing.modulo.t

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

const routes: Routes = [
  { path: '', loadChildren: () => import('./routes/home/home.module').then(m => m.RoutesHomeModule) },
  { path: 'about', loadChildren: () => import('./routes/about/about.module').then(m => m.RoutesAboutModule) },
  { path: '**', redirectTo: '', pathMatch: 'full' }
];

@NgModule({
  imports: [ RouterModule.forRoot(routes, { relativeLinkResolution: 'legacy' }) ],
  exports: [ RouterModule ]
})
export class AppRoutingModule { }

app.componente.ts

import { Component, OnInit } from '@angular/core';
import { NavigationStart, Router } from '@angular/router';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.less'],
})
export class AppComponent implements OnInit {

  constructor(
    private router: Router,
  ) { }

  ngOnInit(): void {
    this.router.events.subscribe(event => {
      if (event instanceof NavigationStart) {
        // outputs "/about" but NEVER "/"
        console.log(event.url);
      }
    });
  }

}

Angolare : 13.0.2
Chrome : 96.0.4664.55
OS : MacOS 12.0.1

angular lazy-loading
2021-11-24 05:42:28
1

Migliore risposta

0

Per saltare il precarico della casa modulo è possibile aggiornare il percorso array come segue.

const routes: Routes = [
  { path: 'home', loadChildren: () => import('./routes/home/home.module').then(m => m.RoutesHomeModule)},
  { path: 'about', loadChildren: () => import('./routes/about/about.module').then(m => m.RoutesAboutModule) },
  { path: '**', redirectTo: '', pathMatch: 'full' }
];

Questo può limitare il precaricamento.

È possibile specificare come path: 'home' invece di path: ''.

2021-11-24 12:54:52

Che modifiche hai fatto ?
Ziad

Aggiornata la mia risposta @Ziad
Jai Saravanan

Home modulo non è precaricato più, ma ho ancora la URL di essere stato riscritto : /about -> / -> /circa
Ziad

Così, quando si danno /about è il reindirizzamento a` /` ?
Jai Saravanan

Sì, per poi tornare al /circa
Ziad

Controllare il codice del componente o auth.guardia, qualsiasi reindirizzamento logica che aveva fatto. Percorsi sembra essere buono.
Jai Saravanan

Lavoro @Ziad ?
Jai Saravanan

In altre lingue

Questa pagina è in altre lingue

Русский
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................