重定向到父路由,而不是刷新页面上的子路由

时间:2020-03-03 12:05:24

标签: angular typescript routes angular-routing

{
        path: '',
        component: componentA,
        children: [
            {
                path: '',
                component: componentB,
                pathMatch: 'full'
            },
            {
                path: 'upload',
                component: UploadComponent,
                children: [
                    {
                        path: 'step_1',
                        component: StepOneComponent,
                        pathMatch: 'full'
                    },
                    {
                        path: 'step_2',
                        component: StepTwoComponent,
                        pathMatch: 'full'
                    },
                    ...

当前行为:

ngOnInit()的{​​{1}}中,我这样做:

UploadComponent

如果您位于ngOnInit() { this.router.navigateTo(['step_1']); } 上并要刷新页面,则会将您重定向到StepTwoComponent

我认为发生这种情况是因为首先正在加载StepOneComponent,它会重定向到UploadComponent而不是当前的地址。

StepOneComponent包括:

UploadComponent.html

问题:

如何刷新到不重定向到<div> <!-- some content --> </div> <div> <!-- some content --> <router-outlet></router-outlet> <!-- some content --> </div> 而是重定向到当前链接?

1 个答案:

答案 0 :(得分:0)

在子级中注册路由class Program { static void Main(string[] args) { string myString = "1231654165152112315461561561651561562165"; var charArray = myString.ToCharArray(); foreach (var item in charArray) { Console.WriteLine(item); } int[] myStringIntegers = Array.ConvertAll(charArray, c => (int)Char.GetNumericValue(c)); Console.WriteLine(myStringIntegers.Length); int i = 0; foreach (var item in myStringIntegers) { Console.WriteLine("Value at pos("+i+") : " + item); i++; } Console.Read(); } } (不完整)和''(通配符路由),以便它们导航到'**'

step_1

{ path: '', component: componentA, children: [ { path: '', component: componentB, pathMatch: 'full' }, { path: 'upload', component: UploadComponent, children: [ { path: 'step_1', component: StepOneComponent, pathMatch: 'full' }, { path: 'step_2', component: StepTwoComponent, pathMatch: 'full' }, // put these 2 new routes at the end { path: '', redirectTo: 'step_1', pathMatch: 'full', }, { path: '**', redirectTo: 'step_1', pathMatch: 'full', }.... 的{​​{1}}中,删除导航到ngOnInit的逻辑。

现在,当您在UploadComponent上刷新时,应该停留在'step_1'上。