Javascript Angular 8路由意外更改查询字符串顺序

Javascript Angular 8路由意外更改查询字符串顺序,javascript,angular,angular-routing,angular-router,angular8,Javascript,Angular,Angular Routing,Angular Router,Angular8,使用Angular 8作为登录页构建一个应用程序,该应用程序在重定向链接中接受动态查询字符串,其中包含一些查询字符串键,如:42=17,例如,当我在浏览器中点击完整链接时,如下所示: http://localhost:4200/success?id1=123&42=17&hash=qwertzuiop 结果:它无意中将序列更改为: http://localhost:4200/success?42=17&id1=123&hash=qwertzuiop 预期的:为了保持查询字符串的相同顺序,我需要根

使用Angular 8作为登录页构建一个应用程序,该应用程序在重定向链接中接受动态查询字符串,其中包含一些查询字符串键,如:
42=17
,例如,当我在浏览器中点击完整链接时,如下所示:

http://localhost:4200/success?id1=123&42=17&hash=qwertzuiop

结果:它无意中将序列更改为:

http://localhost:4200/success?42=17&id1=123&hash=qwertzuiop

预期的:为了保持查询字符串的相同顺序,我需要根据原始url检查哈希字符串(如果更改了),当然,当序列更改时,哈希函数结果也会随之更改


代码示例

app-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { SuccessComponent } from './success/success.component';
import { NotFoundComponent } from './not-found/not-found.component';

const routes: Routes = [
  { path: 'success', component: SuccessComponent },
  { path: '**', component: NotFoundComponent }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }
success.component.ts

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';

@Component({
  selector: 'app-success',
  templateUrl: './success.component.html',
  styleUrls: ['./success.component.scss']
})

export class SuccessComponent implements OnInit {

  constructor(
    private route: ActivatedRoute,
    private router: Router) { }

  ngOnInit() {
    console.log(this.route.snapshot.queryParams);
    // {42: "17", id1: "123", hash: "qwertzuiop"}

    console.log(this.router.routerState.snapshot.url);
    // /success?42=17&id1=123&hash=qwertzuiop
  }
}

在匹配角度路由和导航之前,是否可以截取原始URL?

我不知道这一点,但要解决创建哈希时的问题,请按字母顺序对键进行排序,如果要重新生成哈希,请按相同顺序对键进行排序,那么散列就可以了same@RezaRahmati我不是创建散列的人,只是验证一下,但是谢谢你的帮助reply@BasimHennawi,在javascript中,无法对对象进行排序。对象内部按升序排序,我们无法更改。这就是为什么42远远领先于其他人。@Bearniti这就是为什么我询问如何在角度路由发生之前拦截原始url,但感谢您尝试控制台路由器事件-this.router.events.subscribe((val)=>{const page=this.router.url;const location=window.location.href;});我不知道这一点,但要解决创建哈希时的问题,请按字母顺序对键进行排序,如果要重新生成哈希,请按相同的顺序对键进行排序,然后哈希将被删除same@RezaRahmati我不是创建散列的人,只是验证一下,但是谢谢你的帮助reply@BasimHennawi,在javascript中,无法对对象进行排序。对象内部按升序排序,我们无法更改。这就是为什么42远远领先于其他人。@Bearniti这就是为什么我询问如何在角度路由发生之前拦截原始url,但感谢您尝试控制台路由器事件-this.router.events.subscribe((val)=>{const page=this.router.url;const location=window.location.href;});