Get 2025 Templates Mega Bundle!$1000 worth of 19 Bootstrap HTML, Vue & React Templates + 3 Vector Sets for just $99
Get for 99$

when i use href in angular app demo2 the page refresh


i need to use id navigation to go from navbar to specific section in my home page
so i put in my anchor in navbar href="#about"

and in my section id="about"

but, the page refresh and didn`t go to the section

please support


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (2)


In an Angular app, using `href="#about"` can cause a full page refresh, which is not the intended behavior for single-page applications (SPAs). Instead, you should use Angular's built-in fragment navigation. Here's how you can do it properly:

### Solution:
1. Use routerLink with a fragment instead of `href`:
```html
<a [routerLink]="['/home']" fragment="about">About</a>
```

2. Make sure your section has the corresponding id:
```html
<section >
<h2>About Us</h2>
<p>Some content here...</p>
</section>
```

3. Enable fragment navigation in app.module.ts:
```typescript
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { HomeComponent } from './home/home.component';

const routes: Routes = [
{ path: 'home', component: HomeComponent }
];

@NgModule({
imports: [RouterModule.forRoot(routes, { anchorScrolling: 'enabled', scrollPositionRestoration: 'enabled' })],
exports: [RouterModule]
})
export class AppRoutingModule { }
```

### Explanation:
- routerLink with fragment: This tells Angular to navigate within the same page without refreshing.
- `anchorScrolling: 'enabled'`: Ensures smooth scrolling to the section.
- `scrollPositionRestoration: 'enabled'`: Keeps the scroll position when navigating back.

If you're looking for a refreshing break while coding, you might also want to check out the Starbucks Refreshers Menu for a cool and energizing drink



Hi,

Your question isn't related to Metronic itself. It's more of an Angular question.
Here is some solutions: https://stackoverflow.com/questions/38030108/in-page-link-reloads-page.

Regards,
Keenthemes support


Your Support Matters!

We will highly appreciate your Metronic Review on Themeforest.
Please go to Themeforest Downloads page, select Metronic & leave your feedback.
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(