Class

RouterService

RouterService()

Constructor

# 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.

View Source app/services/router.service.ts, line 14

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.

sequenceDiagram participant C as Component participant R as RouterService participant L as Location C->>R: backToLastPage() R->>L: Dispatch BACK_BUTTON_NAVIGATION event R->>L: Navigate back

View Source app/services/router.service.ts, line 632

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.

sequenceDiagram participant C as Component participant R as RouterService participant W as Window C->>R: getCurrentUrl() R->>R: Get router.url R->>W: Get window.location.pathname alt router.url is '/' and different from pathname R->>R: Use pathname else R->>R: Use router.url end R->>R: Remove leading '/' R-->>C: Return clean URL

View Source app/services/router.service.ts, line 584

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.

sequenceDiagram participant C as Component participant R as RouterService participant W as Window C->>R: getLastUrlSegment() alt Router URL available R->>R: Split router.url by '/' else Router URL not available R->>W: Get window.location.href R->>R: Split href by '/' end R->>R: Extract last segment R-->>C: Return last segment

View Source app/services/router.service.ts, line 555

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.

sequenceDiagram participant C as Component participant R as RouterService participant N as Router Navigation C->>R: getPreviousUrl() R->>N: Get currentNavigation alt previousNavigation exists R->>N: Extract previousNavigation.finalUrl R->>R: Store in previousUrl end R-->>C: Return previousUrl

View Source app/services/router.service.ts, line 610

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.

sequenceDiagram participant C as Component participant R as RouterService C->>R: getQueryParam(param) R->>R: parseAllQueryParams(param) R->>R: Extract first result or undefined R-->>C: Return key-value object or undefined
Parameters:
Name Type Description
param string

The name of the query parameter to retrieve

View Source app/services/router.service.ts, line 504

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.

sequenceDiagram participant C as Component participant R as RouterService C->>R: getQueryParamValue(param) R->>R: parseAllQueryParams(param) R->>R: Extract value from first result or undefined R-->>C: Return string value or undefined
Parameters:
Name Type Description
param string

The name of the query parameter to retrieve

View Source app/services/router.service.ts, line 527

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.

sequenceDiagram participant C as Component participant R as RouterService participant A as ActivatedRoute C->>R: hasQueryParam(param) R->>A: Access snapshot.queryParams R->>R: Check if param exists in queryParams R-->>C: Return boolean result
Parameters:
Name Type Description
param string

The name of the query parameter to check

View Source app/services/router.service.ts, line 481

True if the parameter exists, false otherwise

boolean

Triggers navigation to a specified page using the Ionic NavController. Supports different navigation directions and additional options.

Navigates to a specified page.

sequenceDiagram participant C as Component participant R as RouterService participant N as NavController C->>R: navigateTo(page, direction, options) alt direction is ROOT R->>N: navigateRoot(page, options) else direction is FORWARD R->>N: navigateForward(page, options) else direction is BACK R->>N: navigateBack(page, options) end N-->>R: Return navigation result R-->>C: Return boolean result
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

View Source app/services/router.service.ts, line 664

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

View Source app/services/router.service.ts, line 457

Array