Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to manually trigger browser back button from angular

import { Injectable } from '@angular/core'
import { Location } from '@angular/common'
import { Router, NavigationEnd } from '@angular/router'

@Injectable({ providedIn: 'root' })
export class NavigationService {
  private history: string[] = []

  constructor(private router: Router, private location: Location) {
    this.router.events.subscribe((event) => {
      if (event instanceof NavigationEnd) {
        this.history.push(event.urlAfterRedirects)
      }
    })
  }

  back(): void {
    this.history.pop()
    if (this.history.length > 0) {
      this.location.back()
    } else {
      this.router.navigateByUrl('/')
    }
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: delay external javascript file load 
Javascript :: create object from number 
Javascript :: save js 
Javascript :: currying javascript 
Javascript :: ngif react 
Javascript :: js array string includes 
Javascript :: 9 + 10 
Javascript :: native module rnc_asyncsqlitedbstorage tried to override asyncstorage module 
Javascript :: js example 
Javascript :: react onchange url 
Javascript :: using plice to remove an element from an array in react 
Javascript :: javascript sleep one second 
Javascript :: moment date format 
Javascript :: map in javascript 
Javascript :: map function with params 
Javascript :: js parameter vs argument 
Javascript :: save text of div to localStorage, update localStorage when text is changed 
Javascript :: add marker on map geocoder result mapbox 
Javascript :: load js 
Javascript :: react double render 
Javascript :: jquery class 
Javascript :: logical operators in javascript 
Javascript :: angular inner page in refresh 404 after ng build 
Javascript :: Angle Between Hands of a Clock 
Javascript :: is loop backward 
Javascript :: react without using jsx create element 
Javascript :: react-native-apple-authentication 
Javascript :: react to pdf 
Javascript :: react native border radius not working ios 
Javascript :: javascript add field to array 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =