# new RouterService()
The RouterService provides a unified interface for navigation and route management, abstracting the underlying Angular Router and Ionic NavController functionality. It offers methods for navigating between routes, retrieving URL information, and managing query parameters. This service is designed to simplify navigation patterns and provide consistent behavior across the application.
Service for handling routing operations in the application.
Methods
# backToLastPage() → {void}
Triggers navigation back to the previous page in the browser's history. This method also dispatches a custom event to notify other components about the back navigation.
Navigates back to the previous page.
void
# getCurrentUrl() → {string}
Extracts the current URL path from either the Angular Router or the browser's window location, depending on availability. It also cleans the URL by removing the leading forward slash for consistency.
Retrieves the current URL of the application.
The current URL of the application without the leading slash
string
# getLastUrlSegment() → {string}
Extracts the final path segment from the current URL, which often represents the current page or resource identifier. This method first attempts to use the Angular Router's URL, and falls back to the window location if needed.
Retrieves the last segment of the current URL.
The last segment of the current URL path
string
# getPreviousUrl() → {string}
Extracts the URL of the previous page from the router's navigation history. This information is useful for back navigation and for understanding the user's navigation path through the application.
Retrieves the URL of the previous page.
The URL of the previous page
string
# getQueryParam(param) → {KeyValue|undefined}
Extracts a single query parameter from the current route and returns it as a key-value pair. This method leverages parseAllQueryParams internally and returns the first result or undefined if the parameter doesn't exist.
Retrieves a specific query parameter from the current route.
Parameters:
Name | Type | Description |
---|---|---|
param |
string
|
The name of the query parameter to retrieve |
A key-value object representing the parameter, or undefined if not found
KeyValue
|
undefined
# getQueryParamValue(param) → {string|undefined}
Extracts the value of a single query parameter from the current route. This is a convenience method that handles the extraction and returns just the value rather than a key-value pair.
Retrieves the value of a specific query parameter.
Parameters:
Name | Type | Description |
---|---|---|
param |
string
|
The name of the query parameter to retrieve |
The value of the parameter, or undefined if not found
string
|
undefined
# hasQueryParam(param) → {boolean}
Determines whether a specific query parameter is present in the current route's query parameters. This is useful for conditional logic based on the presence of certain parameters in the URL.
Checks if a query parameter exists in the current route.
Parameters:
Name | Type | Description |
---|---|---|
param |
string
|
The name of the query parameter to check |
True if the parameter exists, false otherwise
boolean
# async navigateTo(page, directionopt, optionsopt) → {Promise.<boolean>}
Triggers navigation to a specified page using the Ionic NavController. Supports different navigation directions and additional options.
Navigates to a specified page.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
page |
string
|
The page to navigate to |
||
direction |
RouteDirections
|
<optional> |
RouteDirections.FORWARD | The direction of navigation |
options |
NavigationOptions
|
<optional> |
Additional navigation options |
A promise that resolves to true if navigation is successful, otherwise false
Promise.<boolean>
# parseAllQueryParams(params) → {Array}
Initializes a new RouterService. The commented line suggests that in a previous version, this service was registered with an injectable registry system, which may have been used for dependency tracking or service discovery.
Creates an instance of RouterService.
Parameters:
Name | Type | Description |
---|---|---|
params |
string
|
Array
|
Array