# Auth0 redirect is not working properly, Angular automatically redirects to base route

**URL:** <https://community.auth0.com/t/auth0-redirect-is-not-working-properly-angular-automatically-redirects-to-base-route/59679>\
**Category:** Get Help\
**Created:** [March 18, 2021, 9:43pm UTC](https://community.auth0.com/t/auth0-redirect-is-not-working-properly-angular-automatically-redirects-to-base-route/59679 "2021-03-18T21:43:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakemangan1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jakemangan1/32/12805_2.png) [@jakemangan1](https://community.auth0.com/u/jakemangan1)\
**Post date:** [March 18, 2021, 9:43pm UTC](https://community.auth0.com/t/auth0-redirect-is-not-working-properly-angular-automatically-redirects-to-base-route/59679/1 "2021-03-18T21:43:23Z")

</div>

I’m trying to set up Auth0 with my Angular app, however when Auth0 redirects back to my Angular app after successful authentication it tries to redirect to `http://localhost:4200/tracker?code=fK0frbSIkXuHAE28&state=cjc4WHdUSnU4U0pSeDlwMjc3c3NJZ0MxcGpsZ3dwX2h2eX42dEJacDJCWg%3D%3D`

This page isn’t allowed to load and then almost instantly redirects back to `http://localhost:4200`

If I try to manually navigate to `http://localhost:4200/tracker?code=fK0frbSIkXuHAE28&state=cjc4WHdUSnU4U0pSeDlwMjc3c3NJZ0MxcGpsZ3dwX2h2eX42dEJacDJCWg%3D%3D`, the app will again force the browser back to `http://localhost:4200`

However if I try to manually navigate to `http://localhost:4200/tracker?code=fK0frbSIkXuHAE28&`, without the `state` parameter in the URL, angular allows the route to activate

I have Auth0 set up so that it will automatically redirect to `http://localhost:4200/tracker` after Authentication, but this redirect being caused by angular is breaking the authentication flow.

I can see that separate navigation events are being raised by the router, so it’s obviously Angular causing the redirect.

What are these “code” and “state” parameters that are coming back with the redirect?

Do I need to specifically state the params that are expected by the route or something? Why is it automatically preventing the route from activating?

```auto
NavigationStart {id: 1, url: "/tracker?code=fK0frbSIkXuHAE28&state=cjc4WHdUSnU4U…SeDlwMjc3c3NJZ0MxcGpsZ3dwX2h2eX42dEJacDJCWg%3D%3D", navigationTrigger: "imperative", restoredState: null}
    id: 1
    navigationTrigger: "imperative"
    restoredState: null
    url: "/tracker? 
    code=fK0frbSIkXuHAE28&state=cjc4WHdUSnU4U0pSeDlwMjc3c3NJZ0MxcGpsZ3dwX2h2eX42dEJacDJCWg%3D%3D"
__proto__ : RouterEvent

core.js:27910 Angular is running in development mode. Call enableProdMode() to enable production mode.

app.component.ts:14 
NavigationStart {id: 2, url: "/", navigationTrigger: "imperative", restoredState: null}
    id: 2
    navigationTrigger: "imperative"
    restoredState: null
    url: "/"
__proto__ : RouterEvent

```

---

<div class="post-metadata">

**Author:** ![jakemangan1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jakemangan1/32/12805_2.png) [@jakemangan1](https://community.auth0.com/u/jakemangan1)\
**Post date:** [March 18, 2021, 11:34pm UTC](https://community.auth0.com/t/auth0-redirect-is-not-working-properly-angular-automatically-redirects-to-base-route/59679/2 "2021-03-18T23:34:30Z")

</div>

Hello,

It seems I’ve found the answer to my question in this thread: [Redirect URI issue after successful login with @auth0/auth0-angular](https://community.auth0.com/t/redirect-uri-issue-after-successful-login-with-auth0-auth0-angular/58111)

The solution was to add `appState: { target: "/url" }` as a parameter to the call to loginWithRedirect method.

I’ve tried this, and it works correctly.

This is really something that should be mentioned in your docs and in the Angular Quickstart and Angular Complete Guide. It’s very confusing for someone new to Auth0 and I believed it was an Angular issue, so I was looking at completely the wrong places for a solution.

I’d like to ask, given that the Auth0 SDK will redirect the user to the base route of their application regardless of the value of the `redirect_url` option in the call to `loginWithRedirect`, what is actually the point of this option? Is it so that the developer can add extra logic to a particular route and have Auth0 redirect to that route to execute the login after authentication? Or perhaps another reason?

I’m just curious why it exists as it’s confusing to expect the SDK to redirect to the supplied URL, when that doesn’t actually happen.

---

<div class="post-metadata">

**Author:** ![EyeG](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/eyeg/32/30789_2.png) [@EyeG](https://community.auth0.com/u/EyeG)\
**Post date:** [July 28, 2021, 12:40am UTC](https://community.auth0.com/t/auth0-redirect-is-not-working-properly-angular-automatically-redirects-to-base-route/59679/3 "2021-07-28T00:40:56Z")

</div>

Thank you for linking this! This link also solved my problem and I agree, it would be nice to have in the Quickstart guide, as I am brand new to Auth0 and pretty new to Angular. Appreciate this post!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 28, 2021, 11:05am UTC](https://community.auth0.com/t/auth0-redirect-is-not-working-properly-angular-automatically-redirects-to-base-route/59679/4 "2021-07-28T11:05:10Z")

</div>

Thanks for sharing that feedback. I’ll make sure to relay it to appropriate team!

---

<div class="post-metadata">

**Author:** ![1sttechpc](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/1sttechpc/32/38079_2.png) [@1sttechpc](https://community.auth0.com/u/1sttechpc)\
**Post date:** [June 16, 2022, 12:11pm UTC](https://community.auth0.com/t/auth0-redirect-is-not-working-properly-angular-automatically-redirects-to-base-route/59679/5 "2022-06-16T12:11:31Z")

</div>

Thanks! it helps me too.

```auto
         <button
  *ngIf="(auth.isAuthenticated$ | async) === false"
  (click)="loginWithRedirect({
    appState: { target: '/YOUR-URL' }
  })">
  Log in
</button>

```

---

<div class="post-metadata">

**Author:** ![Dave22](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@Dave22](https://community.auth0.com/u/Dave22)\
**Post date:** [May 23, 2024, 6:37pm UTC](https://community.auth0.com/t/auth0-redirect-is-not-working-properly-angular-automatically-redirects-to-base-route/59679/6 "2024-05-23T18:37:12Z")

</div>

Hey I implemented that solution as well, and while it solves the issue, it is not solving it perfectly, as my root path component is still loading for less than a second before the last step redirects to the target url. Is there a way around that, so that it goes directly to the target url instead of going to the root first?

---

<div class="post-metadata">

**Author:** ![maiksfd](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@maiksfd](https://community.auth0.com/u/maiksfd)\
**Post date:** [June 29, 2024, 1:26pm UTC](https://community.auth0.com/t/auth0-redirect-is-not-working-properly-angular-automatically-redirects-to-base-route/59679/7 "2024-06-29T13:26:26Z")

</div>

Hi,

i am facing the same small issue (root path component is showing for a split second). I found out that you can just match the redirectUri and the targetPath. So for me the redirectUri is “[http://localhost:4200/users/dashboard](http://localhost:4200/users/dashboard)” and the targetPath is “users/dashboard”. I don’t know if thats the optimal way but it seems to work.

Best regards.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [May 14, 2025, 5:07pm UTC](https://community.auth0.com/t/auth0-redirect-is-not-working-properly-angular-automatically-redirects-to-base-route/59679/8 "2025-05-14T17:07:42Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
