Skip to content

Commit

Permalink
Url anchor support for micro frontends
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleychh authored Mar 14, 2022
1 parent 3038f63 commit 2478386
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 16,174 deletions.
22 changes: 21 additions & 1 deletion client/luigi-client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export declare interface Context {
};
nodeParams?: NodeParams;
pathParams?: PathParams;
anchor?: string;
[key: string]: any;
}

export declare interface NodeParams {
[key: string]: string;
}
Expand Down Expand Up @@ -652,6 +652,26 @@ export type getActiveFeatureToggles = () => Array<String>;
export function getPathParams(): PathParams;
export type getPathParams = () => PathParams;

/**
* Returns the anchor of active URL.
* @returns {String} the anchor string
* @memberof Lifecycle
* @example
* LuigiClient.getAnchor();
*/
export function getAnchor(): String;
export type getAnchor = () => String;

/**
* Sets the anchor of active URL.
* @param {string} anchor
* @memberof Lifecycle
* @example
* LuigiClient.setAnchor('luigi');
*/
export function setAnchor(anchor: String): void;
export type setAnchor = (anchor: String) => void;

/**
* Read search query parameters which are sent from Luigi core
* @memberof Lifecycle
Expand Down
25 changes: 25 additions & 0 deletions client/src/lifecycleManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,5 +527,30 @@ class LifecycleManager extends LuigiClientBase {
getUserSettings() {
return this.currentContext.internal.userSettings;
}

/**
* Returns the current anchor based on active URL.
* @memberof Lifecycle
* @returns anchor of URL
* @example
* LuigiClient.getAnchor();
*/
getAnchor() {
return this.currentContext.internal.anchor || '';
}

/**
* Sends anchor to Luigi Core. The anchor will be added to the URL.
* @param {string} anchor
* @memberof Lifecycle
* @example
* LuigiClient.setAnchor('luigi');
*/
setAnchor(anchor) {
helpers.sendPostMessageToLuigiCore({
msg: 'luigi.setAnchor',
anchor
});
}
}
export const lifecycleManager = new LifecycleManager();
3 changes: 2 additions & 1 deletion client/src/linkManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export class linkManager extends LuigiClientBase {
relative: false,
link: '',
newTab: false,
preserveQueryParams: false
preserveQueryParams: false,
anchor: ''
};
}

Expand Down
6 changes: 6 additions & 0 deletions client/src/luigi-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ class LuigiClient {
luigiClientInit() {
return lifecycleManager.luigiClientInit();
}
getAnchor() {
return lifecycleManager.getAnchor();
}
setAnchor(value) {
return lifecycleManager.setAnchor(value);
}

/**
* @private
Expand Down
Loading

0 comments on commit 2478386

Please sign in to comment.