home
  • Blog
  • Home
  • Projects
    • Ember
    • EmberData
    • Ember CLI
6.2
  • Packages
    • @ember/application
    • @ember/application/namespace
    • @ember/array
    • @ember/array/proxy
    • @ember/canary-features
    • @ember/component
    • @ember/component/template-only
    • @ember/controller
    • @ember/debug
    • @ember/debug/container-debug-adapter
    • @ember/debug/data-adapter
    • @ember/destroyable
    • @ember/engine
    • @ember/helper
    • @ember/object
    • @ember/object/core
    • @ember/object/evented
    • @ember/object/mixin
    • @ember/object/observable
    • @ember/object/promise-proxy-mixin
    • @ember/object/proxy
    • @ember/owner
    • @ember/renderer
    • @ember/routing
    • @ember/routing/hash-location
    • @ember/routing/history-location
    • @ember/routing/location
    • @ember/routing/none-location
    • @ember/routing/route
    • @ember/routing/route-info
    • @ember/routing/router
    • @ember/routing/router-service
    • @ember/routing/transition
    • @ember/runloop
    • @ember/service
    • @ember/template
    • @ember/test
    • @ember/utils
    • @glimmer/tracking
    • @glimmer/tracking/primitives/cache
    • rsvp
  • Classes
    • Application
    • ApplicationInstance
    • ApplicationInstance.BootOptions
    • ArrayProxy
    • Component
    • ComputedProperty
    • ContainerDebugAdapter
    • CoreObject
    • DataAdapter
    • Ember.Controller
    • Ember.NativeArray
    • Ember.Templates.helpers
    • Ember.Test
    • Ember.Test.QUnitAdapter
    • EmberArray
    • EmberENV
    • EmberObject
    • EmberRouter
    • Engine
    • EngineInstance
    • EventTarget
    • Evented
    • Factory
    • FactoryManager
    • FullName
    • HashLocation
    • Helper
    • HistoryLocation
    • Location
    • Mixin
    • MutableArray
    • Namespace
    • NoneLocation
    • ObjectProxy
    • Observable
    • Owner
    • Promise
    • PromiseProxyMixin
    • RegisterOptions
    • Renderer
    • Resolver
    • Route
    • RouteInfo
    • RouteInfoWithAttributes
    • RouterService
    • SafeString
    • Service
    • TestAdapter
    • Transition

Class Location public


Defined in: packages/@ember/routing/location.ts:5
Module: @ember/routing/location
Since: v5.0.0
import Location from '@ember/routing/location';

Location defines an interface to be implemented by location APIs. It is not user-constructible; the only valid way to get a Location is via one of its concrete implementations.

Implementations

You can pass an implementation name (hash, history, none) to force a particular implementation to be used in your application.

  • See HashLocation.
  • See HistoryLocation.
  • See NoneLocation.

Location API

Each location implementation must provide the following methods:

  • getURL: returns the current URL.
  • setURL(path): sets the current URL.
  • replaceURL(path): replace the current URL (optional).
  • onUpdateURL(callback): triggers the callback when the URL changes.
  • formatURL(url): formats url to be placed into href attribute.

Calling setURL or replaceURL will not trigger onUpdateURL callbacks.

Custom implementation

Ember scans app/locations/* for extending the Location API.

Example:

import HistoryLocation from '@ember/routing/history-location';

export default class MyHistory {
  implementation = 'my-custom-history';

  constructor() {
    this._history = HistoryLocation.create(...arguments);
  }

  create() {
    return new this(...arguments);
  }

  pushState(path) {
     this._history.pushState(path);
  }
}


Methods

formatURL (url) public

Module: @ember/routing/location

Defined in packages/@ember/routing/location.ts:111

url
String

the url to format

Formats url to be placed into href attribute.

replaceURL (url) public

Module: @ember/routing/location

Defined in packages/@ember/routing/location.ts:93

url
String

the new URL to replace the current URL with.

Replace the current URL (optional). Calling replaceURL will not trigger onUpdateURL callbacks.

setURL (url) public

Module: @ember/routing/location

Defined in packages/@ember/routing/location.ts:82

url
String

the new URL to update to.

Sets the current URL. Calling setURL will not trigger onUpdateURL callbacks.

Properties

cancelRouterSetup public

Module: @ember/routing/location

Defined in packages/@ember/routing/location.ts:63

If the location needs to redirect to a different URL, it can cancel routing by setting the cancelRouterSetup property on itself to false.

currentURL public

Module: @ember/routing/location

Defined in packages/@ember/routing/location.ts:74

The current URL.

On this page


Methods

  • formatURL
  • replaceURL
  • setURL

Properties

  • cancelRouterSetup
  • currentURL
Team Sponsors Security Legal Branding Community Guidelines
Twitter GitHub Discord Mastodon

If you want help you can contact us by email, open an issue, or get realtime help by joining the Ember Discord.

© Copyright 2025 - Tilde Inc.
Ember.js is free, open source and always will be.


Ember is generously supported by
blue Created with Sketch.