question

MattAbbene-7586 avatar image
0 Votes"
MattAbbene-7586 asked AgaveJoe commented

Handling Server side routing errors with built in client side routing

Hello, I have a question regarding the cleanest/easiest way to fix a routing issue. To start off, I'm using the .NET 5 framework, and have the following setup in my Startup.cs:


 public void ConfigureServices(IServiceCollection services) {
     ...
     services.AddSpaStaticFiles(configuration => { configuration.RootPath = "UI"; });
   .....
 }
    
    
    
 public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
             ....
             app.UseRouting();
             app.UseSpaStaticFiles();
             app.UseAuthorization();
    
             app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
    
             app.UseSpa(spa =>
             {
                 if (!env.IsDevelopment()) return;
                 spa.Options.SourcePath = "UI/";
                 spa.UseVueCli();
             });
    
    
 }

Now, my problem seems to be an issue with the server side routing behavior, however I will let you diagnose. Basically, I am returning a Redirect method that redirects to a CLIENT SIDE route, (the route does NOT exist on the server side), and so when my client receives the response, it always receives the response as a 404 error message. However, if I click the request in the network tab in my browser debugger, it ends up redirecting to the client endpoint properly. I was wondering how I could resolve this 404 error and smoothly redirect to that client endpoint.

Thanks!

dotnet-csharpdotnet-aspnet-core-generaldotnet-aspnet-core-webapi
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

There are ASP.NET Core tags you can post to for help.

0 Votes 0 ·

Thanks Duane, will change to include those!

0 Votes 0 ·

A redirect causes the browser to do an HTTP GET to the address found in the location header. Typically, a SPA has its own routing. It does not make sense to return a redirect (HTTP 302) from a server. Typically the SPA route address is returned within a standard 200 (ok) and the JavaScript library does the redirect.

0 Votes 0 ·

0 Answers