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