LocationServices interface handles low-level URL read/write operations and listens for URL changes.
Overview
- PushStateLocationService - HTML5 pushState API
- HashLocationService - Hash-based URLs
- MemoryLocationService - In-memory URLs (no browser integration)
Methods
url()
Gets or updates the URL.newurl- The new URL value (optional)replace- When true, replaces current history entry instead of appending (optional)state- The history’s state object for pushState (optional)
Getting the URL
When called without arguments, returns the current URL normalized using the internal path/search/hash values. Example:Setting the URL
Whennewurl is provided, updates the URL.
Example:
path()
Gets the path part of the current URL.search()
Gets the search part of the current URL as an object.hash()
Gets the hash part of the current URL.onChange()
Registers a low-level URL change handler.callback- Function called when the URL changes
dispose()
Cleans up the location service.Implementation Notes
PushStateLocationService
Uses the HTML5 History API (pushState, replaceState).
Features:
- Clean URLs without hash
- Requires server-side configuration
- Works with
<base href="...">
http://example.com/app/path/to/state?query=value
HashLocationService
Uses URL hash for routing. Features:- Works without server configuration
- Hash prefix configurable (default:
!) - URLs contain
#
http://example.com/app/#!/path/to/state?query=value
MemoryLocationService
Stores URL in memory (no browser integration). Features:- Useful for testing
- No browser history integration
- No actual URL changes
Creating Custom Implementations
Implement theLocationServices interface to create custom location handling: