Home > Enterprise >  Angular route not matching with hash
Angular route not matching with hash

Time:11-17

I have these types of routes in angular 12

const routes: Routes = [
  { path: '', component: HomeComponent },
  { path: 'about', component: AboutComponent },
  { path: 'login', component: LoginComponent, canActivate: [LoggedInAuthGuard] },
  { path: 'register', component: RagisterComponent, canActivate: [LoggedInAuthGuard] },
  { path: 'pagenotfound', component: PagenotfoundComponent },
  { path: '404', component: PagenotfoundComponent },
  { path: 'profile', component: ProfileComponent },
  { path: '**', redirectTo: '/404' },

];

issue is i have several links on my sites with href='#' so when i click on those links i'm getting redirected to home page. Is there any way if i click on these blank links it should stay on that page only without being redirected. Thanks

CodePudding user response:

Hello you can use href="javascript:void(0)" on your href so It will stop the redirect or you can use onclick="return false;".

Example 1

<a href="javascript:void(0)">link</a>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

Example 2

<a href="" onclick="return false;">link</a>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

If you have any doubt then let me know

CodePudding user response:

Instead of href="#" you should use

routerLink

on your anchor tag. Using href causes that the whole page reload agian.

  • Related