The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/angular/bridgeReactAngularRouting.ts

49 lines
1.3 KiB

import { ILocationService } from 'angular';
import { RouteParamsProvider } from '../core/navigation/patch/RouteParamsProvider';
import { RouteProvider } from '../core/navigation/patch/RouteProvider';
import { AngularLocationWrapper } from './AngularLocationWrapper';
import { coreModule } from './core_module';
// Neutralizing Angular’s location tampering
// https://stackoverflow.com/a/19825756
const tamperAngularLocation = () => {
coreModule.config([
'$provide',
($provide: any) => {
$provide.decorator('$browser', [
'$delegate',
($delegate: any) => {
$delegate.onUrlChange = () => {};
$delegate.url = () => '';
return $delegate;
},
]);
},
]);
};
// Intercepting $location service with implementation based on history
const interceptAngularLocation = () => {
coreModule.config([
'$provide',
($provide: any) => {
$provide.decorator('$location', [
'$delegate',
($delegate: ILocationService) => {
$delegate = new AngularLocationWrapper() as unknown as ILocationService;
return $delegate;
},
]);
},
]);
coreModule.provider('$route', RouteProvider);
coreModule.provider('$routeParams', RouteParamsProvider);
};
export function initAngularRoutingBridge() {
tamperAngularLocation();
interceptAngularLocation();
}