Microsoft Edge导航到angular 2上的路由后添加参数 [英] Microsoft Edge adds parameters after navigating to a route on angular 2
问题描述
我有一个表单,该表单分为两个步骤,第一个表单填充对象的主要部分,第二个表单填充子部分.有一种方法可以从Form2导航回Form1,该方法可在Chrome和Firefox上运行,但是对于Microsoft Edge来说似乎添加了"/?object",这是我在代码中没有做的事情.
I have a form being filled in two steps, the first form fills in the main part of an object and the second, the sub-part. There is a method that navigates back from form2 to form1 that works on Chrome and Firefox, but with Microsoft Edge it seems to add "/?object", and it's something that I'm not doing in code.
我的按钮从Form2返回到Form1
my button to go back from form2 to form1
<button class="btn btn-default pull-right" (click)="onCancel()">{{ 'button.back' | translate }}</button>
我的方法onCancel()
my method onCancel()
onCancel() {
this.goal.target = this.target;
this.service.setGoalToSave(this.goal);
if (this.isEditing) {
this.router.navigate(['goals/goalForm', this.goal.goalId.toString()]);
} else {
this.router.navigate(['goals/goalForm']);
}
}
Microsoft Edge导航至
Microsoft Edge navigates to
But that isn't a valid route, so it redirects to my main page.
任何人都知道导致此问题的原因或如何解决?
Anyone knows what is causing this or how can I fix it?
推荐答案
要解决此问题,请将type ="button"添加到button标记中. Edge显然假定任何没有显式类型的按钮都是type ="submit",为此它以表格形式发布值.
To fix this problem, add type="button" to the button tag. Edge is apparently assuming that any button without an explicit type is type="submit", for which it is posting the values in the form.
我已在页面中明确包含form标记,以便可以访问.ts代码中的form属性.我删除了该表单标签和相关代码,并且导航在Edge中有效.因此Edge似乎以为我的按钮是一个提交按钮.将type ="button"包含在button属性中之后,我能够重新放置form标记,并且一切仍然有效.
I had explicitly included the form tag in my page so that I could access the form properties in the .ts code. I removed that form tag and associated code, and the navigation works in Edge. So Edge seems to be assuming that my button was a submit button. After including type="button" in the button attributes, I was able to put the form tag back in, and it all still worked.
这篇关于Microsoft Edge导航到angular 2上的路由后添加参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!