" />
" />
"/>
DEVHIDE
  • Home (current)
  • About
  • Contact
  • Cookie
  • Home (current)
  • About
  • Contact
  • Cookie
  • Disclaimer
  • Privacy
  • TOS
Login Or Sign up

Angular 6 - RouterLink navigates but not changing URL

10.6k Views Asked by balachander j At 01 June 2018 at 18:50 2025-12-20T03:13:01.880000

app.component.html

<nav>
 <a routerLink="/dashboard"></a>
 <a routerLink="/reports"></a>
<nav>
<main role="main" class="page-container">
  <router-outlet></router-outlet>
</main>

app-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { DashboardComponent } from './dashboard/dashboard.component';
import { ReportsComponent } from './reports/reports.component';

const routes: Routes = [
  { path: 'dashboard', component: DashboardComponent },
  { path: 'reports', component: ReportsComponent },
  { path: '',
    redirectTo: '/dashboard',
    pathMatch: 'full'
  }];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { DashboardComponent } from './dashboard/dashboard.component';
import { ReportsComponent } from './reports/reports.component';


@NgModule({
  declarations: [
    AppComponent,
    DashboardComponent,
    ReportsComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {

}

With the above code, I see that on click of the nav links, am able to navigate to the corresponding component but for some reason, URL is not getting updated.

Not sure if am missing something pretty basic here. Please help.

angular angular-cli angular-router routelink
Original Q&A
1

There are 1 best solutions below

2
Serhii Andronik Serhii Andronik On 07 June 2018 at 15:37 BEST ANSWER

if you are running hybrid app(with upgrade module) add useHash to router config

imports: [RouterModule.forRoot(routes, { useHash: true, enableTracing: true })],

Related Questions in ANGULAR

  • Is it possible to use ES5 JavaScript with Angular 2 instead of TypeScript?
  • Module '"angular2/angular2"' has no exported member 'For'
  • import syntax in typescript creating another js file in visual studio
  • Separate ts file for imports
  • How to use an AngularJS 2 component multiple times in the same page?
  • injectables not working in angular 2.0 latest build 26
  • Does angular2 bootstrap have a way to dynamically target elements like it does in angular 1.x
  • Import {} from location is not found in VS Code using TypeScript and Angular 2
  • Angular 2/Typescript: require not found
  • ng-switch in Angular2
  • Angular 2 import issue: "Zone already exported on window the object!"
  • How to make FileReader work with Angular2?
  • Writing the most basic Unit test in Angular 2?
  • Angular2: Creating child components programmatically
  • AngularJS - TypeError: Cannot read property 'canonicalUrl' of undefined

Related Questions in ANGULAR-CLI

  • Running a single test file
  • Errro running ng serve - module has no exported member
  • 404 error when try to access a direct url in different modules with angular-cli server
  • Cloning a repo based on Angular CLI
  • External JavaScript library in angular-cli project throws error that $root.document is undefined
  • Angular cli for existing github project
  • [email protected] (2016-12-15) NOT on npm
  • Cannot GET with Angular 2 CLI build
  • Handle url redirects in angular-cli application deployed to github pages
  • Error using jsonwebtoken with angular-cli application
  • Specify order of Styles in angular-cli.json
  • Angular, Bootstrap 4, angular-cli - where to place dependent scss and import it?
  • Module not found: Error: Can't resolve
  • Ag-grid and Angular2 using angular-cli
  • Angular 2 CLI so much time compiling

Related Questions in ANGULAR-ROUTER

  • How to implement RouteReuseStrategy shouldDetach for specific routes in Angular 2
  • Routing With ID in Angular 4
  • Cannot read property 'outlets' of null in Angular 4
  • Angular 4 Router links not working after redirect
  • How to get children of route
  • routerLink doesn't work when generated via pipes
  • lazy-loaded child route loads twice in Angular
  • How do you mock ActivatedRoute
  • Angular 4 Cannot match any routes, escaping with %2F
  • Angular4 Set Var if Route == 'settings'
  • Importing a lazy-loaded module with routes in a module with a route breaks routing
  • ANALYZE_FOR_ENTRY_COMPONENTS not working in production to load modules dynamicly
  • Router infinite loop with second canActivate guard on lazy-loaded modules
  • Angular how to get the non activated children routes
  • Angular 4 application rendering issue on Mobile Firefox

Related Questions in ROUTELINK

  • .net HTML.RouteLink passes parameter as key-value pair not rout
  • How to pass a string type for MapRoute?
  • How to make my gatsby link work properly in netlify?
  • Insert current URL into @Html.RouteLink parameter to build a link
  • Angular 6 - RouterLink navigates but not changing URL
  • Html.ActionLink, Url.ActionLink and Html.RouteLink return empty urls
  • tooltip for html.RouteLink
  • Actionresult doesnt get called by routelink. Formcollection the culprit?
  • Asp.net MVC add textbox value to routelink
  • Html.Action link and Html.RouteLink
  • How to use fragment in Ajax.RouteLink?
  • C# MVC: User Password Reset Controller: Issues with email addresses as usernames
  • Can an MVC2 or MVC3 html.routelink contain &laquo and &raquo?
  • Angular2 RouteLink doesn't work in "a" tag but it's work when I tip it in navigation bar of browser
  • RouteLink in HtmlHelper?

Trending Questions

  • UIImageView Frame Doesn't Reflect Constraints
  • Is it possible to use adb commands to click on a view by finding its ID?
  • How to create a new web character symbol recognizable by html/javascript?
  • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
  • Heap Gives Page Fault
  • Connect ffmpeg to Visual Studio 2008
  • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
  • How to avoid default initialization of objects in std::vector?
  • second argument of the command line arguments in a format other than char** argv or char* argv[]
  • How to improve efficiency of algorithm which generates next lexicographic permutation?
  • Navigating to the another actvity app getting crash in android
  • How to read the particular message format in android and store in sqlite database?
  • Resetting inventory status after order is cancelled
  • Efficiently compute powers of X in SSE/AVX
  • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

Popular # Hahtags

javascript python java c# php android html jquery c++ css ios sql mysql r reactjs

Popular Questions

  • How do I undo the most recent local commits in Git?
  • How can I remove a specific item from an array in JavaScript?
  • How do I delete a Git branch locally and remotely?
  • Find all files containing a specific text (string) on Linux?
  • How do I revert a Git repository to a previous commit?
  • How do I create an HTML button that acts like a link?
  • How do I check out a remote Git branch?
  • How do I force "git pull" to overwrite local files?
  • How do I list all files of a directory?
  • How to check whether a string contains a substring in JavaScript?
  • How do I redirect to another webpage?
  • How can I iterate over rows in a Pandas DataFrame?
  • How do I convert a String to an int in Java?
  • Does Python have a string 'contains' substring method?
  • How do I check if a string contains a specific word?
.

Copyright © 2021 Jogjafile Inc.

  • Disclaimer
  • Privacy
  • TOS
  • Homegardensmart
  • Math
  • Aftereffectstemplates