skip to Main Content

Iam testing my Angular website and have the problem that I cant reach sublinks.

e.g.

https://testing.my-site.de
-works.
-Click on a link to “/main” works too and leads me there.

But calling directly:
https://testing.my-site.de/main
gives me a 404.

Is it a Webserver/https settings I miss?

Thanks in advance for any hint.

Gregor

2

Answers


  1. If you’re hosting Angular inside Web API for example you’ll need to do something like this in your Startup.cs to change request to index.html when using routing.

    Same principle would apply elsewhere I guess.

     public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            {
               app.UseDefaultFiles();
    
                app.UseMvc();
    
                app.MapWhen(x => !x.Request.Path.Value.StartsWith("/api"), builder =>
                {
                    builder.Use((context, next) =>
                    {
                        context.Request.Path = new PathString("/index.html");
                        return next();
                    });
                });
            }
    
    Login or Signup to reply.
  2. In Apache redirect calls (/*) to index.html. If you have some api eg. /api just exclude it.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search