Angular 12:角度转换Queryparams转换为编码URL
我最近做了ng update
然后遇到了问题。所以基本上我有一条路线 (/book)
和一个查询参数:
localhost:4200/book?success=true&successId=1
或
localhost:4200/book?success=false&errorId=1
Angular 正在将其转换为单个路由,该路由当然不会在 路由模块:
本地主机: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"
}
}
I recently did ng update
and went then in problems. So basically I have a route (/book)
and a query param with:
localhost:4200/book?success=true&successId=1
or
localhost:4200/book?success=false&errorId=1
Angular is converting that to a single route, which is of course not registered in the
routing module:
localhost:4200/book%3Fsuccess%3Dtrue&successId%3D1
My 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"
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为我的app.routing.module:
之前:
之后:
由于我删除了路径:'**'它的工作原理!
It was because of my app.routing.module:
before:
after:
since I removed the path: '**' it works just as expected!