0

Not sure how to ask the question correctly, but here goes:

Environment: ASP.NET Server, Angular 8 and not a SPA. Each ASP view reloads angular.

app.module.ts:

  providers: [
    { provide: APP_BASE_HREF, useValue: '/Scripts/ng' },

I can go to an address like https://localhost:5999/location which is configured in the routes, but when I get there the browsers address bar has https://localhost:5999/Scripts/ng/location in it.

How do I get it back to the relative path of Angular?

thanks

2 Answers 2

1

You might need to add the <base href="/"> element to your html file where the Angular app is bootstrapped (usually index.html), the docs explain it a bit more (https://angular.io/guide/router#base-href) but I think it is telling the framework where to begin the relative routes from.

Otherwise it might be the order of the routes in your configuration which is inadvertently redirecting to Scripts/ng/location when location is accessed. Generally speaking the routes in the config object are matched from top to bottom (or beginning to end), the first matched path is used.

Sign up to request clarification or add additional context in comments.

2 Comments

Good try, but didn't really make a difference. I guess I could do a redirect on the server if it finds /Scripts/ng, but feels kind of hacky.
Ah ok that's a shame, this might a long shot but I always set the server to redirect all 404 and 403 requests to /index.html with a 200 status just to make sure that direct requests to any paths get through to the angular router instead of being kicked back from the server, not sure if that's relevant in this case though
0

After changing to <base href="/"> and changing { provide: APP_BASE_HREF, useValue: '/' }, it started working the way I expected. Not sure I totally understand but that is for another day.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.