mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-01 19:00:21 +03:00
feat: add baseURL for redoc
This commit is contained in:
parent
3d410b6002
commit
a978927903
|
@ -70,6 +70,10 @@ export class AppStore {
|
|||
// update position statically based on hash (in case of SSR)
|
||||
MenuStore.updateOnHistory(history.currentId, this.scroll);
|
||||
|
||||
if (options.baseURL) {
|
||||
history.setBaseURL(options.baseURL);
|
||||
}
|
||||
|
||||
this.spec = new SpecStore(spec, specUrl, this.options);
|
||||
this.menu = new MenuStore(this.spec, this.scroll, history);
|
||||
|
||||
|
|
|
@ -6,21 +6,35 @@ const EVENT = 'hashchange';
|
|||
|
||||
export class HistoryService {
|
||||
private _emiter;
|
||||
private _baseURL: string | undefined;
|
||||
|
||||
constructor() {
|
||||
this._emiter = new EventEmitter();
|
||||
this.bind();
|
||||
}
|
||||
|
||||
setBaseURL(baseURL: string) {
|
||||
this._baseURL = baseURL;
|
||||
}
|
||||
|
||||
get baseURL(): string | undefined {
|
||||
return this._baseURL;
|
||||
}
|
||||
|
||||
get currentId(): string {
|
||||
return IS_BROWSER ? decodeURIComponent(window.location.hash.substring(1)) : '';
|
||||
}
|
||||
|
||||
linkForId(id: string) {
|
||||
if (!id) {
|
||||
return '';
|
||||
const links: string[] = [];
|
||||
if (this._baseURL) {
|
||||
links.push(this._baseURL);
|
||||
}
|
||||
return '#' + id;
|
||||
if (id) {
|
||||
links.push(id);
|
||||
}
|
||||
const link = links.join('/');
|
||||
return link === '' ? '' : '#' + link;
|
||||
}
|
||||
|
||||
subscribe(cb): () => void {
|
||||
|
|
|
@ -123,6 +123,11 @@ export class MenuStore {
|
|||
}
|
||||
let item: IMenuItem | undefined;
|
||||
|
||||
const baseURL = this.history.baseURL;
|
||||
if (baseURL && id.startsWith(baseURL + '/')) {
|
||||
id = id.substring(baseURL.length + 1);
|
||||
}
|
||||
|
||||
item = this.flatItems.find(i => i.id === id);
|
||||
|
||||
if (item) {
|
||||
|
|
|
@ -56,6 +56,8 @@ export interface RedocRawOptions {
|
|||
hideFab?: boolean;
|
||||
minCharacterLengthToInitSearch?: number;
|
||||
showWebhookVerb?: boolean;
|
||||
|
||||
baseURL?: string;
|
||||
}
|
||||
|
||||
export function argValueToBoolean(val?: string | boolean, defaultValue?: boolean): boolean {
|
||||
|
|
Loading…
Reference in New Issue
Block a user