Microsoft Edge 在导航到 angular 2 上的路线后添加参数 [英] Microsoft Edge adds parameters after navigating to a route on angular 2

查看:41
本文介绍了Microsoft Edge 在导航到 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

http://localhost:8080/my-service/?target01=&target02=&target03=&target04=&target05=&target06=&target07=&target08=&target09=&target10=&target11=&target12=&annualTarget=

但这不是一个有效的路由,所以它重定向到我的主页.

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 上的路线后添加参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆