LocationConfig interface returns information about the location configuration, primarily used when building URLs.
Overview
- BrowserLocationConfig - Browser-based configuration
- MemoryLocationConfig - In-memory configuration
Methods
port()
Gets the port number.80, 443, 3000).
Example:
protocol()
Gets the protocol."http", "https").
Example:
host()
Gets the hostname."localhost", "example.com").
Example:
baseHref()
Gets the base HREF."http://localhost/approot/").
The base href is used as the prefix for all application URLs. It’s typically set using the HTML <base> tag or configured programmatically.
Example:
html5Mode()
Returns whether HTML5 mode is enabled.true if running in HTML5 mode (pushState), false if using hash-based routing.
Example:
hashPrefix()
Gets or sets the hash prefix.newprefix- The new hash prefix to set (optional)
# and the route path.
Example:
dispose()
Cleans up the location config.Building Absolute URLs
The information fromLocationConfig can be used to build absolute URLs:
Implementation Notes
BrowserLocationConfig
Reads configuration from the browser’swindow.location and HTML <base> tag.
Features:
- Automatically detects protocol, host, port from browser
- Reads base href from
<base>tag - Supports both pushState and hash modes
MemoryLocationConfig
Provides configurable in-memory configuration. Features:- Useful for testing and server-side rendering
- All values are configurable
- No browser dependencies
Creating Custom Implementations
Implement theLocationConfig interface for custom location configuration: