Search code examples
angularangular-ui-routerangular7-router

Remove localhost:4200/xxx from router link


I want to redirect to another link using router link in angular 7 but localhost:4200/dashboard is getting appended to the link to which I want to redirect.

 <a  [routerLink]="https://google.com">Google</a>

When I click on Google, It should redirect to https://google.com but localhost:4200/dashboard/https://google.com is being called.


Solution

  • routerLink is for internal routing of Angular. If you want to navigate to an external URL, just use href with a tag:

    <a  href="https://google.com">Google</a>
    

    RouterLink: https://angular.io/api/router/RouterLink