각 기본 경로는 항상 사

0

질문

나는 두 가지 경로:

  • 홈["]
  • 에 대해[''에 대해]

때 나는 이에 대해 직접 브라우저,내가 주 2 일:

  • 나의 가정 모듈을 미리 로드(는 반면 나는 요청에 대한/)
  • URL rewritted 다음과 같이:/대>/->/에 대

응용 프로그램-routing.모듈입니다.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.구성 요소입니다.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);
      }
    });
  }

}

모:13.0.2
Chrome:96.0.4664.55
OS:MacOS12.0.1

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

최고의 응답

0

을 건너 미리의 집에 모듈을 업데이트할 수 있습니다로 편안 다음과 같습니다.

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' }
];

이것을 제한할 수 있습니다 미리로.

으로 지정할 수 있습니다 path: 'home'path: ''.

2021-11-24 12:54:52

어떤 변화했는가?
Ziad

업데이트 내 대답@Ziad
Jai Saravanan

가정 모듈을 미리 로드되지 않은 더 이상 하지만 나는 아직도의 URL 을 가지고 rewritting:/대>/->/에 대
Ziad

그래서 때 당신 /about 그것은 리다이렉션하는`/`?
Jai Saravanan

네 그것은 간/에 대
Ziad

체크인 코드의 구성 요소 또는 인증.감시 모든 리디렉션을 논리를 만들었다. 귀하의 노선에 좋을 것 같습니다.
Jai Saravanan

그것은 노력하고 있습니다@Ziad?
Jai Saravanan

다른 언어로

이 페이지는 다른 언어로되어 있습니다

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