Salesforce

Navigating Browser History (Magic xpa 4.x)

« Go Back

Information

 
Created BySalesforce Service User
Approval Process StatusPublished
Objective
Description

Navigating Browser History

Your browser can keep the record of all the pages you have visited while you navigate from one page (website) to another. You can access these previously visited pages in the browser with Angular and Java.

Angular Methods to Navigate the Browser History

Angular provides Location service ($location) to be able to navigate through the history stored pages.

forward()

Navigates forward in the browser's history.

Syntax: forward(): void

Parameters: nil

Return value: void

back()

Navigates backward in the browser's history.

Syntax: back(): void

Parameters: nil

Return value: void

Java Method to Refresh the Web Page

The $location service of Angular allows you to change only URL; it does not allow you to reload the web page. Java provides Location object to be able to reload or refresh the complete web page.

reload()

Reloads the current web page.

Syntax: location.reload(forceGet)

Parameter: forceGet (Boolean). This is an optional parameter to specify the manner of reloading. The default value of forceGet is False. In this case, the browser reloads the current page from cache. If forceGet is set to True, the browser reloads the current page from the server.

location.reload(true)

In case you need to reload only one component then Magic provides you the internal event SubformRefresh.

Return value: void

Example

You can see the code snippet that implements navigation through the browser’s history:

import {

Component, ChangeDetectorRef

} from '@angular/core';

import {Location} from '@angular/common';

import {

TaskBaseMagicComponent,

magicProviders,

MagicServices

} from "@magic-xpa/angular";

import { Router } from '@angular/router';

@Component({

selector: 'mga-form1',

providers: [...magicProviders, Location],

templateUrl: './form1.component.html'

}) export class form1 extends TaskBaseMagicComponent {

constructor ( ref: ChangeDetectorRef,

magicServices: MagicServices, private locationService: Location, private router: Router) {

super(ref, magicServices);

}

forward() {

this.locationService.forward();

}

back() {

this.locationService.back();

}

reload() {

location.reload();

}

}

Reference
Attachment 
Attachment