Javascript 角度4:单击带有参数的链接

Javascript 角度4:单击带有参数的链接,javascript,angular,Javascript,Angular,我是个新手。我有一个锚定标签,点击它应该重定向到我需要传递参数的链接。我不确定我的方法是对还是错。但更重要的是,我如何传递参数?我需要指导 myFunc() { console.log("function called"); this.router.navigate(['../myURL'], {queryParams:{rurl: "someId"}}) } import {Router} from '@angular/router'; this.router = Router;

我是个新手。我有一个锚定标签,点击它应该重定向到我需要传递参数的链接。我不确定我的方法是对还是错。但更重要的是,我如何传递参数?我需要指导

myFunc() {
  console.log("function called");
  this.router.navigate(['../myURL'], {queryParams:{rurl: "someId"}})
 }
import {Router} from '@angular/router';

this.router = Router;              
form.component.html:

<a (click)="myFunc()" href="" target="_blank">Go to mymodule</a><br />
myFunc() {
  console.log("function called");
  this.router.navigate(['../myURL'], {queryParams:{rurl: "someId"}})
 }
import {Router} from '@angular/router';

this.router = Router;              
<a [routerLink]="['/route-name', id]" href="">Go to mymodule</a>
import { Router } from '@angular/router';

constructor(private router: Router) { }

myFunc = function () {
        this.router.navigateByUrl('/route-name', {queryParams:{param-key: param-value}});
};
IMHO,您应该使用以下方式导航:

myFunc() {
  console.log("function called");
  this.router.navigate(['../myURL'], {queryParams:{rurl: "someId"}})
 }
import {Router} from '@angular/router';

this.router = Router;              
同样,不要忘记像这样导入
路由器

myFunc() {
  console.log("function called");
  this.router.navigate(['../myURL'], {queryParams:{rurl: "someId"}})
 }
import {Router} from '@angular/router';

this.router = Router;              

注意:在URL使路由器上升一级之前使用
。/

如果要在应用程序外部重定向:

myFunc() {
  console.log("function called");
  this.router.navigate(['../myURL'], {queryParams:{rurl: "someId"}})
 }
import {Router} from '@angular/router';

this.router = Router;              
myFunc(){
   window.location.href = `full_url?rurl=${encodeURIComponent(display)})`;
}
myFunc(){
this.router.navigate(['/navigation_route'], {queryParams:{returnRoute: 'any_path'});
}
如果要导航到应用程序内部的页面:

myFunc() {
  console.log("function called");
  this.router.navigate(['../myURL'], {queryParams:{rurl: "someId"}})
 }
import {Router} from '@angular/router';

this.router = Router;              
myFunc(){
   window.location.href = `full_url?rurl=${encodeURIComponent(display)})`;
}
myFunc(){
this.router.navigate(['/navigation_route'], {queryParams:{returnRoute: 'any_path'});
}

使用[routerLink]:

<a (click)="myFunc()" href="" target="_blank">Go to mymodule</a><br />
myFunc() {
  console.log("function called");
  this.router.navigate(['../myURL'], {queryParams:{rurl: "someId"}})
 }
import {Router} from '@angular/router';

this.router = Router;              
<a [routerLink]="['/route-name', id]" href="">Go to mymodule</a>
import { Router } from '@angular/router';

constructor(private router: Router) { }

myFunc = function () {
        this.router.navigateByUrl('/route-name', {queryParams:{param-key: param-value}});
};
使用navigateByUrl:

<a (click)="myFunc()" href="" target="_blank">Go to mymodule</a><br />
myFunc() {
  console.log("function called");
  this.router.navigate(['../myURL'], {queryParams:{rurl: "someId"}})
 }
import {Router} from '@angular/router';

this.router = Router;              
<a [routerLink]="['/route-name', id]" href="">Go to mymodule</a>
import { Router } from '@angular/router';

constructor(private router: Router) { }

myFunc = function () {
        this.router.navigateByUrl('/route-name', {queryParams:{param-key: param-value}});
};

美元('display').attr('href')是多少?为什么在这里使用jquery?我需要调用一个servlet。我试着用jquery。虽然没有成功。那href link呢?这是案例1(例如,外部应用程序-支付网关)