简体   繁体   English

Chrome 后退按钮不适用于 MVC 应用程序到 spa(Angular + API)

[英]Chrome back button does not work MVC app to spa(Angular + API)

My application consists with two parts MVC and Angular + API, i have issue with back button on the browser when trying to navigate back from MVC part to the SPA .我的应用程序由两部分组成 MVC 和 Angular + API,当我尝试从 MVC 部分导航回 SPA 时,浏览器上的后退按钮有问题。 For example例如

i navigate to the main page of my application https://localhost:5001/en-us(SPA. Angular + API) and from that page i navigate to the following page https://localhost:5001/en-us/blog(MVC) , and when i press back button on chrome the url got updated on the browser but no page actually refreshed, i mean it does not go back to the main site.我导航到我的应用程序的主页https://localhost:5001/en-us(SPA. Angular + API)并从该页面导航到以下页面https://localhost:5001/en-us/blog(MVC) ,当我按下 chrome 上的后退按钮时,浏览器上的 url 得到了更新,但实际上没有页面刷新,我的意思是它不会返回主站点。

Note: Back button is working as expected in scope of MVC or SPA scope.注意:后退按钮在 MVC 或 SPA 范围内按预期工作。 For example if i navigate from https://localhost:5001/en-us/blog to the https://localhost:5001/en-us/blog/Articles/1 and after that presss back button it will work as expected, and the same for SPA part.例如,如果我从 https://localhost:5001/en-us/blog 导航到 https://localhost:5001/en-us/blog/Articles/1,然后按下后退按钮,它将按预期工作, SPA部分也一样。 The problem only with mvc app back to spa app.只有 mvc 应用程序回到 spa 应用程序的问题。

Since the url of the MVC app is underneath the Angular app, Angular is probably presuming that it has to render those pages as well.由于 MVC 应用程序的 url 位于 Angular 应用程序下方,因此 Angular 可能认为它也必须呈现这些页面。

Is it an option to use another base url for Angular?是否可以选择为 Angular 使用另一个基本网址? Or use HashLocationStrategy to let the routing use # inside the app?或者使用HashLocationStrategy让路由在应用程序内使用#? Please refer to https://angular.io/guide/router#locationstrategy-and-browser-url-styles请参考https://angular.io/guide/router#locationstrategy-and-browser-url-styles

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM