Angular 12:angular 将 Queryparams 转换为编码的 url
Angular 12: angular converting Queryparams to encoded urls
我最近做了 ng update
然后遇到了问题。所以基本上我有一条路线 (/book)
和一个查询参数:
localhost:4200/book?success=true&successId=1
或
localhost:4200/book?success=false&errorId=1
Angular 正在将其转换为单个路由,当然没有在
路由模块:
localhost:4200/book%3Fsuccess%3Dtrue&successId%3D1
我的package.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 }
];
因为我删除了路径:“**”,它按预期工作!
我最近做了 ng update
然后遇到了问题。所以基本上我有一条路线 (/book)
和一个查询参数:
localhost:4200/book?success=true&successId=1
或
localhost:4200/book?success=false&errorId=1
Angular 正在将其转换为单个路由,当然没有在 路由模块:
localhost:4200/book%3Fsuccess%3Dtrue&successId%3D1
我的package.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 }
];
因为我删除了路径:“**”,它按预期工作!