{
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>
而是重定向到当前链接?
答案 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'
上。