The angular 2 router is failing to navigate properly when using the history forward/backward button

The history push state feature is not working properly with the Angular 2 router in both Chrome and Firefox. The forward button never works, and the backward button only works for 2 steps before the UI stops responding to it.

Here is the code I am using:

app.component.ts

import { Component } from '@angular/core';
import { ROUTER_DIRECTIVES, Routes } from '@angular/router';
import { CrisisListComponent } from './crisis-list.component';
import { HeroListComponent }   from './hero-list.component';
import { Login }   from './login';
@Component({
  selector: 'my-app',
  template: `
    <h1>Component Router</h1>
    <nav>
      <a [routerLink]="['/home']">Crisis Center</a>
      <a [routerLink]="['/login']">Login</a>
      <a [routerLink]="['/heroes']">Heroes</a>
    </nav>
    <router-outlet></router-outlet>
  `,
  directives: [ROUTER_DIRECTIVES]
})
@Routes([
  {path: '/home', component: CrisisListComponent},
  {path: '/heroes',        component: HeroListComponent},
  {path : '/login' , component:Login},
  {path: '*',        component: CrisisListComponent}
])
export class AppComponent { }

login.ts

import { Component } from '@angular/core';
import { ROUTER_DIRECTIVES, Routes } from '@angular/router';
import { LoginMobile }   from './login/login_mobile';
import { LoginEmail }   from './login/login_email';

@Component({
  template: `
    <h2>{{val}}</h2>
    <p>Login here</p>\n\
    <a [routerLink]="['/login/mobile']">Mobile</a>
    <a [routerLink]="['/login/email']">Email</a>
    <router-outlet></router-outlet>
`,
  directives: [ROUTER_DIRECTIVES]
})
@Routes([
  {path : '/mobile' , component:LoginMobile},
  {path : '/email' , component:LoginEmail}
])
export class Login {
    val = "kwik.Social";
}

login/login_email.ts

import { Component } from '@angular/core';
@Component({
  template: `
    <p>Login here</p>
    <input type="email" placeholder="Email" [(ngModel)]="email" />\n\
    <p>Your Email is {{email}} </p>
`
})
export class LoginEmail {
    email = "kwik.Social";
}

Answer №1

After patiently waiting for some time, I decided to give the router by NGRX team a try. This router offers a variety of features such as Guards, Multiple Components, Child Components, and comprehensive support for the Full History API. The only thing I find lacking is that the History API itself does not offer a way to retrieve user-entered values in text fields and scroll positions. If this functionality were available, Ajax Pages could become even more seamless and consistent.

Edit

The NGRX router has now been deprecated, and the Angular Router - inspired by the NGRX router - is now in place and performing well.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide to iterating through a queue of promises (sequentially handling asynchronous messages)

Currently, I am working on processing a queue of promises (which are representations of messages) in a specific order and using AngularJS for the task. Just to give you an idea, let's say that I have a method called connect() which returns a promise ...

Encountering a problem where updating the selected option in a dropdown does not properly refresh the HTML

I am currently working with a dropdown menu containing countries. Initially, the selected item is set to Ukraine. <select id="country" name="country"> <option value="US">USA</option> <option value="UG">Uganda</option> ...

Two sets of buttons, however, one set is carrying out the incorrect function

I am trying to create two button sets that, when clicked, are supposed to angle the text below them at 45 degrees. However, I am facing an issue where both set 1 and set 2 only control the text linked to button 1. I need each button set to control their ...

Include the insertion button in the Tiny MCE Editor

Currently, I am in the process of developing my own plugin to integrate into the list of TinyMCE v4 plugins. So far, I have successfully added a button to the menu that opens a pop-up when clicked. In this pop-up, users can input data which is then added t ...

A Guide to Displaying Django Forms.TimeField in 12-hour Format on a Template

I am facing an issue with my Django form when creating and updating model data. Upon creation, I simply input 6:30 pm using the timepicker, which works fine. However, when editing an existing record, Django displays the initial time in 24-hour format (e.g. ...

Exploring color gradation using GLSL shaders in WebGL

I want to achieve a black color in the center of my disk with a gradient effect towards the outer edges. However, when I use the GLSL code "gl_FragColor = vec4( vec3( vUv, 0.17 ), 1. );" I encounter some issues. varying vec2 vUv; void main() { vUv ...

What is the purpose of directives in Angular 2?

I am struggling to grasp the distinction between these two @Directive and directives: [HeroAppMainComponent] In the scenario presented below @Component({ selector: 'hero-app', template: ` <h1>Tour of Heroes</h1> ...

Testing URL Parameters in JEST with an API

Seeking integration tests using Jest for an API endpoint. Here's the specific endpoint: http://localhost/universities/ucla/class/2013/studentalis/johndoe. When tested with a put request, it returns 201 on Postman. However, the testing encountered a t ...

Enabling scrolling for a designated section of the website

Example Link to Plunker <clr-main-container> <div class="content-container"> <div class="content-area"> <div class="row"> <div class="col-xs-9" style="height:100%; border-right: 1px solid rgb(204, 204, 204); padding-ri ...

Creating custom directives in AngularJS can be a rewarding and powerful

When working with two directives, a situation arose where it was necessary to clear the value in Directive A by using a button located in Directive B. However, when attempting to do this using typical DOM manipulation tools like jQuery, an error occurred w ...

Looking to showcase initial API data upon page load without requiring any user input?

Introduction Currently, I am retrieving data from the openweatherAPI, which is being displayed in both the console and on the page. Issue My problem lies in not being able to showcase the default data on the frontend immediately upon the page's fir ...

Is the Date Epoch a reliable form of unique identification?

Currently, I'm developing a Node API and encountered a situation where I need to create a unique 15-digit random number for a model without using autoincrement. The challenge is to ensure that the generated number is not trivial. I am hesitant about ...

Hide the menu even if the user clicks outside of it or anywhere on the webpage

I have a menubar code that is functioning correctly. However, I would like to make an enhancement. Currently, when I click outside of the menubar, it does not hide or close. I want the menubar to be hidden when I click anywhere on the webpage while the men ...

React Error: Unable to Call function this.state.Data.map

I'm encountering an issue with mapping objects in ReactJS. Even though I am able to fetch data, when I try to map it, I receive the following error: this.state.Data.map is not a function Here's the code snippet: import React, { Component } fro ...

Is there a more efficient way to handle post data without increasing its size when encoding JSON within a URI

I have a significant amount of data to post, and it needs to be minimized for performance reasons. Initially, my data consists of JavaScript objects which I then convert to JSON format before sending it via POST request. The issue is that my data include ...

Having trouble compiling Angular CLI version 8.3.21 with the command ng serve

Upon trying to compile my first Angular app, I encountered an error when running ng serve: ERROR in ./src/styles.css (./node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/raw-css-loader.js!./node_modules/postcss-loader/src??embedded! ...

I do not send JSON Express post for receiving

I have a question regarding sending JSON data to my Express server using request. However, when Express receives the data, it doesn't seem to be in the correct JSON format. Below, I will share the code related to this issue. The JSON I am sending ...

Exploring data retrieval from nested arrays of objects in TypeScript/Angular

I have an API that returns an object array like the example below. How can I access the nested array of objects within the JSON data to find the role with roleid = 2 when EmpId is 102 using TypeScript? 0- { EmpId: 101, EmpName:'abc' Role : ...

Jade will be loaded after Angular finishes loading and resolving all variables

I have an uncomplicated page built with nodejs, utilizing angular on the front end and nodejs on the back end. When I load data in a controller using $http like so - angular.module('student').controller('StudentDashBoardController', f ...

Custom objects do not return true for Symbol.hasInstance

The TypeScript playground encounters an issue with the Symbol.hasInstance built-in symbol, while it functions properly for other symbols. Testing other symbol methods such as Symbol.match and Symbol.replace show no problems, but Symbol.hasInstance is not ...