Created an Angular SPA with some routes on it like:
/messages
/messages/:id
With ng serve
I can access to that pages with the URL localhost:4200/messages
and localhost:4200/messages/:id
Then I built the solution and copied the generated content to an ASP.NET Web API 2 project. On the project controller, I set the default route ("/")
to return the SPA index.html
file, so if I run the app I get the SPA with the URL: localhost:51384
From the links on the page I get to the messages/:id page, and the showing URL on the browser is:
localhost:51384/messages/:id
From Angular doc I know that the shown URL is local and is not sent to the server. If I try to access to that URL manually, I get an error:
HTTP Error 404.0 - Not Found
That's obvious because on the WebAPI controller there is no rule for /messages/:id
.
I am aware that I have a concept problem, but is there a way to access to the SPA routes with the WebAPI's URL? If not, what is the correct way to integrate a SPA into a .NET project and access to the SPA routes? Should they be accessed only through the page and not through the URL?
Thanks in advance, feel free to comment or vote positive/negative