问题描述
我有一个表单分两步填写,第一个表单填写对象的主要部分,第二个填写子部分.有一种方法可以从 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" 添加到按钮标记.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.
我已在页面中明确包含表单标记,以便我可以访问 .ts 代码中的表单属性.我删除了那个表单标签和相关代码,导航在 Edge 中工作.所以 Edge 似乎假设我的按钮是一个提交按钮.在按钮属性中包含 type="button" 后,我能够将表单标记放回去,并且一切仍然有效.
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 上的路线后添加参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!