경로 2에 상관없이 페이지로드시 기본 경로로 이동하도록 Angular 2 애플리케이션을 설정하려고하지만 경로가 작동하지 않는 것 같습니다.앱로드시 특정 페이지로 강제 리디렉션
로직을 내 app-component의 ngOnInit에 추가하여 내 홈 경로로 리디렉션하지만 무시됩니다.
import {Component, OnInit} from '@angular/core';
import {Router} from "@angular/router";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
constructor(private router: Router) {}
closeApplication() {
electron.ipcRenderer.send('close-app');
}
ngOnInit() {
console.log('I am being run.');
this.router.navigate(['']);
}
}
는 여기에 몇 가지 상황에 맞는, 내가 사용자가 기본 페이지에서 응용 프로그램을 시작하면 환상적인 노력하고 선형 사용자 흐름을 가진 전자 응용 프로그램을 만드는 오전 내 라우팅 설정
import {LoginComponent} from "./login/login.component";
import {HomeComponent} from "./home/home.component";
import {AuthGuard} from "./shared/security/auth.guard";
import {RegisterComponent} from "./register/register.component";
import {ListingComponent} from "./listing/listing.component";
import {RedirectGuard} from "./shared/security/redirect.guard";
import {WelcomeComponent } from "./welcome/welcome.component";
export const routerConfig = [
{ path: 'login', component: LoginComponent, canActivate: [RedirectGuard] },
{ path: 'register', component: RegisterComponent, canActivate: [RedirectGuard] },
{ path: 'home', component: HomeComponent, canActivate: [AuthGuard],
children: [
{
path: '',
component: ListingComponent
},
{
path: 'listing/:id',
component: ListingComponent
}
]
},
{ path: '', component: WelcomeComponent },
{ path: '**', component: HomeComponent },
];
입니다. 3 페이지를 새로 고치고 새로 고치면 전체 응용 프로그램 상태가 모두 엉망입니다. 나는 상태를 유지하기 위해 데이터베이스를 사용하지 않고 있으며 로컬 저장소에 저장하는 것이 최종 목표에 너무 많은 부담이라고 생각합니다.
건배!
라우팅 구성을 게시하십시오. –
자, 자. 나는 그것을 추가했다 – Luca