mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
parent
f75c10f30e
commit
07ceb70278
6 changed files with 39 additions and 8 deletions
|
@ -4,13 +4,16 @@
|
|||
|
||||
## ApplicationStart.getUrlForApp() method
|
||||
|
||||
Returns a relative URL to a given app, including the global base path.
|
||||
Returns an URL to a given app, including the global base path. By default, the URL is relative (/basePath/app/my-app). Use the `absolute` option to generate an absolute url (http://host:port/basePath/app/my-app)
|
||||
|
||||
Note that when generating absolute urls, the protocol, host and port are determined from the browser location.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
getUrlForApp(appId: string, options?: {
|
||||
path?: string;
|
||||
absolute?: boolean;
|
||||
}): string;
|
||||
```
|
||||
|
||||
|
@ -19,7 +22,7 @@ getUrlForApp(appId: string, options?: {
|
|||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| appId | <code>string</code> | |
|
||||
| options | <code>{</code><br/><code> path?: string;</code><br/><code> }</code> | |
|
||||
| options | <code>{</code><br/><code> path?: string;</code><br/><code> absolute?: boolean;</code><br/><code> }</code> | |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ export interface ApplicationStart
|
|||
|
||||
| Method | Description |
|
||||
| --- | --- |
|
||||
| [getUrlForApp(appId, options)](./kibana-plugin-public.applicationstart.geturlforapp.md) | Returns a relative URL to a given app, including the global base path. |
|
||||
| [getUrlForApp(appId, options)](./kibana-plugin-public.applicationstart.geturlforapp.md) | Returns an URL to a given app, including the global base path. By default, the URL is relative (/basePath/app/my-app). Use the <code>absolute</code> option to generate an absolute url (http://host:port/basePath/app/my-app)<!-- -->Note that when generating absolute urls, the protocol, host and port are determined from the browser location. |
|
||||
| [navigateToApp(appId, options)](./kibana-plugin-public.applicationstart.navigatetoapp.md) | Navigate to a given app |
|
||||
| [registerMountContext(contextName, provider)](./kibana-plugin-public.applicationstart.registermountcontext.md) | Register a context provider for application mounting. Will only be available to applications that depend on the plugin that registered this context. Deprecated, use [CoreSetup.getStartServices()](./kibana-plugin-public.coresetup.getstartservices.md)<!-- -->. |
|
||||
|
||||
|
|
|
@ -580,7 +580,6 @@ describe('#start()', () => {
|
|||
|
||||
it('creates URLs with path parameter', async () => {
|
||||
service.setup(setupDeps);
|
||||
|
||||
const { getUrlForApp } = await service.start(startDeps);
|
||||
|
||||
expect(getUrlForApp('app1', { path: 'deep/link' })).toBe('/base-path/app/app1/deep/link');
|
||||
|
@ -588,6 +587,16 @@ describe('#start()', () => {
|
|||
expect(getUrlForApp('app1', { path: '//deep/link//' })).toBe('/base-path/app/app1/deep/link');
|
||||
expect(getUrlForApp('app1', { path: 'deep/link///' })).toBe('/base-path/app/app1/deep/link');
|
||||
});
|
||||
|
||||
it('creates absolute URLs when `absolute` parameter is true', async () => {
|
||||
service.setup(setupDeps);
|
||||
const { getUrlForApp } = await service.start(startDeps);
|
||||
|
||||
expect(getUrlForApp('app1', { absolute: true })).toBe('http://localhost/base-path/app/app1');
|
||||
expect(getUrlForApp('app2', { path: 'deep/link', absolute: true })).toBe(
|
||||
'http://localhost/base-path/app/app2/deep/link'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('navigateToApp', () => {
|
||||
|
|
|
@ -272,8 +272,13 @@ export class ApplicationService {
|
|||
takeUntil(this.stop$)
|
||||
),
|
||||
registerMountContext: this.mountContext.registerContext,
|
||||
getUrlForApp: (appId, { path }: { path?: string } = {}) =>
|
||||
http.basePath.prepend(getAppUrl(availableMounters, appId, path)),
|
||||
getUrlForApp: (
|
||||
appId,
|
||||
{ path, absolute = false }: { path?: string; absolute?: boolean } = {}
|
||||
) => {
|
||||
const relUrl = http.basePath.prepend(getAppUrl(availableMounters, appId, path));
|
||||
return absolute ? relativeToAbsolute(relUrl) : relUrl;
|
||||
},
|
||||
navigateToApp: async (appId, { path, state }: { path?: string; state?: any } = {}) => {
|
||||
if (await this.shouldNavigate(overlays)) {
|
||||
this.appLeaveHandlers.delete(this.currentAppId$.value!);
|
||||
|
@ -364,3 +369,10 @@ const updateStatus = <T extends AppBase>(app: T, statusUpdaters: AppUpdaterWrapp
|
|||
...changes,
|
||||
};
|
||||
};
|
||||
|
||||
function relativeToAbsolute(url: string) {
|
||||
// convert all link urls to absolute urls
|
||||
const a = document.createElement('a');
|
||||
a.setAttribute('href', url);
|
||||
return a.href;
|
||||
}
|
||||
|
|
|
@ -593,11 +593,17 @@ export interface ApplicationStart {
|
|||
navigateToApp(appId: string, options?: { path?: string; state?: any }): Promise<void>;
|
||||
|
||||
/**
|
||||
* Returns a relative URL to a given app, including the global base path.
|
||||
* Returns an URL to a given app, including the global base path.
|
||||
* By default, the URL is relative (/basePath/app/my-app).
|
||||
* Use the `absolute` option to generate an absolute url (http://host:port/basePath/app/my-app)
|
||||
*
|
||||
* Note that when generating absolute urls, the protocol, host and port are determined from the browser location.
|
||||
*
|
||||
* @param appId
|
||||
* @param options.path - optional path inside application to deep link to
|
||||
* @param options.absolute - if true, will returns an absolute url instead of a relative one
|
||||
*/
|
||||
getUrlForApp(appId: string, options?: { path?: string }): string;
|
||||
getUrlForApp(appId: string, options?: { path?: string; absolute?: boolean }): string;
|
||||
|
||||
/**
|
||||
* Register a context provider for application mounting. Will only be available to applications that depend on the
|
||||
|
|
|
@ -101,6 +101,7 @@ export interface ApplicationStart {
|
|||
currentAppId$: Observable<string | undefined>;
|
||||
getUrlForApp(appId: string, options?: {
|
||||
path?: string;
|
||||
absolute?: boolean;
|
||||
}): string;
|
||||
navigateToApp(appId: string, options?: {
|
||||
path?: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue