Developed an Angular single-page application with specific routes:
/messages
/messages/:id
By using ng serve
, I can navigate to these pages at URLs like localhost:4200/messages
and localhost:4200/messages/:id
After building the solution, I transferred the content to an ASP.NET Web API 2 project. In the project's controller, I configured the default route ("/")
to display the SPA's index.html
file. This allows me to access the SPA at URL: localhost:51384
Clicking links on the page takes me to the messages/:id page, showing the following URL in the browser:
localhost:51384/messages/:id
Consulting Angular documentation reveals that this URL is local and not sent to the server. Attempting to manually visit this URL results in an error:
HTTP Error 404.0 - Not Found
This occurs because there is no defined rule for /messages/:id
in the WebAPI controller.
Recognizing a fundamental issue, is there a way to access the SPA routes using the WebAPI's URL? If not, what is the correct method for integrating an SPA into a .NET project and accessing its routes? Should they only be accessed through navigation on the page rather than directly via the URL?
Thank you in advance, your feedback is appreciated.