turbogui-angular
Version:
A library that tries to help with the most common user interface elements on several frameworks and platforms
167 lines • 7.61 kB
TypeScript
/**
* TurboGUI is A library that helps with the most common and generic UI elements and functionalities
*
* Website : -> http://www.turbogui.org
* License : -> Licensed under the Apache License, Version 2.0. You may not use this file except in compliance with the License.
* License Url : -> http://www.apache.org/licenses/LICENSE-2.0
* CopyRight : -> Copyright 2018 Edertone Advanded Solutions. https://www.edertone.com
*/
import { OnDestroy } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { LocalesBaseService } from './locales-base.service';
import * as i0 from "@angular/core";
/**
* Global service that helps with application routing and related functionalities.
* It is defined as an abstract class so it must be extended in our application to be used.
* We must declare a static array of routes that will be used to define the routes of the application.
*/
export declare abstract class RouterBaseService implements OnDestroy {
private readonly router;
private readonly titleService;
/**
* Indicates whether the title manager has been initialized.
* This should only be done once, typically at application startup.
*/
private _isTitleManagerInitialized;
/**
* @see getCurrentRouteTitle
*/
private _currentRouteTitle;
/**
* @see getCurrentBrowserTitle
*/
private _currentBrowserTitle;
/**
* Subscription to router events. This is used to update the current route URL
*/
private _routerSubscription;
/**
* BehaviorSubject that holds the current route URL.
* This allows components to reactively subscribe to route changes.
*/
private readonly _currentRoute;
/**
* Instance of the LocalesService to be used for translations.
* It will be provided by the methods that require it.
* This is not injected in the constructor as the locales service class is an abstract class, and we
* need the custom implementation of the service to be provided by the application that extends it.
*/
private _localesService;
constructor(router: Router, titleService: Title);
/**
* Updates the current route URL in the BehaviorSubject.
* This is called internally after each navigation event.
*/
private _updateCurrentRoute;
/**
* Checks if the current route matches the specified route.
*
* @param route The route to check against the current route.
*
* @returns True if we are actually at the specified route, false otherwise.
*/
isRouteCurrent(route: string): boolean;
/**
* Gets the current value of the route URL synchronously.
* For example, if the current route is `/user/123`, it will return `/user/123`.
* Notice that the base URL is not included in the returned value.
*/
getCurrentRoute(): string;
/**
* The current route title, translated using the LocalesService.
* This is updated automatically after each navigation event if the title manager is initialized.
*/
getCurrentRouteTitle(): string;
/**
* The current browser title, which may include prefixes or suffixes.
* This is updated automatically after each navigation event if the title manager is initialized.
*/
getCurrentBrowserTitle(): string;
/**
* Gets the current value of the route absolute URL synchronously.
*
* For example, if the current route is `/user/123` and the base href is `http://example.com/app/`, it will return `http://example.com/app/user/123`.
*/
getCurrentRouteAbsolute(): string;
/**
* Gets the value of a specific route parameter by its key from the current route.
*
* For example, if the current route is `/user/123`, and you call this method with `key` as `id`, it will return `123`.
* The name of the parameter must match the one defined in the route configuration on your application (e.g., `{ path: 'user/:id', component: UserComponent }`).
*
* @param key The key of the route parameter to retrieve.
*
* @returns The value of the specified route parameter, or undefined if it does not exist.
*/
getCurrentRouteParamValue(key: string): any;
/**
* Gets the value of a specific query parameter by its key from the current route.
* For example, if the current route is `/search?query=angular`, and you call this method with `key` as `query`, it will return `angular`.
*
* @param key The key of the query parameter to retrieve.
*/
getQueryParamValue(key: string): any;
/**
* Sets or updates the value of a specific query parameter in the current route.
* For example, if the current route is `/search?query=angular`, and you call this method with `key` as `page` and `value` as `2`,
* it will navigate to `/search?query=angular&page=2`.
*
* @param key The key of the query parameter to set or update.
* @param value The value to set for the specified query parameter.
*/
setQueryParamValue(key: string, value: string): void;
/**
* Removes a specific query parameter from the current route.
* For example, if the current route is `/search?query=angular&page=2`, and you call this method with `key` as `page`,
* it will navigate to `/search?query=angular`.
*
* @param key The key of the query parameter to remove.
*/
removeQueryParam(key: string): void;
/**
* Initializes the title management feature to automatically refresh the browser title based on the current
* URL route. It Must be called once, typically at application startup
*
* To correctly translate the route title, We expect the route definitions to have the following properties:
*
* - titleKey: The key to be used to get the title from the translation bundle.
* - titleBundle: The bundle to be used to get the title from the translation bundle.
*
* (Translations will be done using the LocalesService from this same library).
*
* Example of a Route using this feature:
* // Home route
* { path: '', component: HomePageComponent,
* data: { titleKey: 'HOME', titleBundle: 'turbodepot/user-interface'} },
*
* @param localesService An instance of the already initialized LocalesService to be used for translations.
* @param prefix A text to be added before the computed title.
* @param sufix A text to be added after the computed title.
*/
initializeAutoTranslateTitleByRoute(localesService: LocalesBaseService, prefix?: string, sufix?: string): void;
/**
* Aux method: Updates the browser title based on the current route's data properties.
* This is called after each navigation event to ensure the title is always up-to-date.
*
* @param prefix A text to be added before the computed title.
* @param sufix A text to be added after the computed title.
*/
private updateTitleFromCurrentRoute;
/**
* Navigates to the specified route.
*
* @param route The route to navigate to.
*/
navigateTo(route: string): void;
/**
* Automatically called when the service is destroyed.
* We use it to clean up subscriptions and other resources.
*
* Usially not necessary to call this manually.
*/
ngOnDestroy(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<RouterBaseService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<RouterBaseService>;
}
//# sourceMappingURL=router-base.service.d.ts.map