Angular 12:将Queryparams转换为编码的url



我最近做了ng update,然后遇到了问题。所以基本上我有一条路线(/book)和一个查询参数:

localhost:4200/book?成功=真&successId=1

localhost:4200/book?成功=错误&errorId=1

Angular正在将其转换为单个路由,当然该路由没有在路由模块:

localhost:4200/book%3Fsuccess%3True&成功ID%3D1

我的软件包.json:

{
"name": "frontend",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"private": true,
"dependencies": {
"@angular/animations": "~12.0.1",
"@angular/cdk": "~12.2.13",
"@angular/common": "^12.0.5",
"@angular/compiler": "~12.0.1",
"@angular/core": "~12.0.1",
"@angular/forms": "~12.0.1",
"@angular/material": "~12.2.13",
"@angular/platform-browser": "~12.0.1",
"@angular/platform-browser-dynamic": "~12.0.1",
"@angular/router": "~12.0.1",
"@js-temporal/polyfill": "^0.4.0",
"@material/progress-indicator": "^13.0.0",
"@ngx-translate/core": "^14.0.0",
"@ngx-translate/http-loader": "^7.0.0",
"flag-icons": "^6.0.3",
"install": "^0.13.0",
"ngx-cookie-service": "^13.1.2",
"ngx-translate": "0.0.1-security",
"npm": "^8.3.1",
"rxjs": "~6.6.0",
"tslib": "^2.1.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "~12.0.1",
"@angular/cli": "~12.0.1",
"@angular/compiler-cli": "~12.0.1",
"@types/jasmine": "~3.6.0",
"@types/node": "^12.11.1",
"jasmine-core": "~3.7.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"typescript": "~4.2.3"
}
}

这是因为我的app.routing.module:

之前:

const routes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'home', component: HomeComponent },
{ path: 'login', component: CreateAccComponent },
{ path: 'book', component: BookComponent },
{ path: 'location', component: LocationComponent },
{ path: 'openings', component: OpeningsComponent },
{ path: 'pictures', component: PicturesComponent },
{ path: 'roomtour', component: RoomtourComponent },
{ path: 'account', component: AccountComponent },
{ path: 'admin', component: AdminPanelComponent },
{ path: 'bookingProcess', component: BookingProcessComponent },
{ path: '**', component: DefaultComponent}
];

之后:

const routes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'home', component: HomeComponent },
{ path: 'login', component: CreateAccComponent },
{ path: 'book', component: BookComponent },
{ path: 'location', component: LocationComponent },
{ path: 'openings', component: OpeningsComponent },
{ path: 'pictures', component: PicturesComponent },
{ path: 'roomtour', component: RoomtourComponent },
{ path: 'account', component: AccountComponent },
{ path: 'admin', component: AdminPanelComponent },
{ path: 'bookingProcess', component: BookingProcessComponent }
];

由于我删除了路径:"**",它的工作原理与预期的一样!

最新更新