• Overview
@angular/common

HashLocationStrategy

Class
stable

A LocationStrategy used to configure the Location service to represent its state in the hash fragment of the browser's URL.

API

  class HashLocationStrategy extends LocationStrategy implements OnDestroy {}  

constructor

HashLocationStrategy
@param_platformLocationPlatformLocation
@param_baseHrefstring | undefined

onPopState

void
@returnsvoid

getBaseHref

string
@returnsstring

path

string
@paramincludeHashboolean
@returnsstring

prepareExternalUrl

string
@paraminternalstring
@returnsstring

pushState

void
@paramstateany
@paramtitlestring
@parampathstring
@paramqueryParamsstring
@returnsvoid

replaceState

void
@paramstateany
@paramtitlestring
@parampathstring
@paramqueryParamsstring
@returnsvoid

forward

void
@returnsvoid

back

void
@returnsvoid

getState

unknown
@returnsunknown

historyGo

void
@paramrelativePositionnumber
@returnsvoid

Description

A LocationStrategy used to configure the Location service to represent its state in the hash fragment of the browser's URL.

For instance, if you call location.go('/foo'), the browser's URL will become example.com#/foo.

Usage Notes

Example

import {HashLocationStrategy, Location, LocationStrategy} from '@angular/common';import {Component} from '@angular/core';@Component({ selector: 'hash-location', providers: [Location, {provide: LocationStrategy, useClass: HashLocationStrategy}], template: ` <h1>HashLocationStrategy</h1> Current URL is: <code>{{ location.path() }}</code ><br /> Normalize: <code>/foo/bar/</code> is: <code>{{ location.normalize('foo/bar') }}</code ><br /> `, standalone: false,})export class HashLocationComponent { location: Location; constructor(location: Location) { this.location = location; }}
Jump to details