Redoc: Hash navigation is colliding with the existing hash navigation

Created on 26 Sep 2018  路  4Comments  路  Source: Redocly/redoc

Using ReDoc as not a stand alone application, but a part of a framework that's an SPA.
I am using ant.design, a react application as a boiler plate. I want to integrate ReDoc on one of its tab.
I already have a route provider in the application (ex: localhost:8000/#/dashboard/workspace). now while I am trying to use ReDoc component RedocStandalone, while navigating, it already uses this # string, which is causing problem while navigation.

I want something, so that I could access the ReDoc app such after my URL - localhost:8000/#/dashboard/workspace/#section/Authentication, where I need to replace second # with encoded # to navigate smoothly!

Or is there any other way of implementing this, I am unaware of? Please help.

@RomanGotsiy

enhancement feature help wanted

Most helpful comment

For future travelers using HashRouter - my workaround was to disable location updates altogether by patching the MenuStore activate function. Navigation still works, you just don't get the url state:

import { RedocStandalone, MenuStore } from "redoc";

let originalActivate = MenuStore.prototype.activate;

MenuStore.prototype.activate = function(menuItem) {
  // Call activate() and pass through the menuItem, but set both `updateLocation` and `rewriteHistory` to false
  // https://github.com/Redocly/redoc/blob/42696a01ba8ef27523da40c07a5e61ba606e247f/src/services/MenuStore.ts#L197-L199
  originalActivate.apply(this, [menuItem, false, false]);
};

export default RedocStandalone;

All 4 comments

You can fix it by using history-based (pushState, popState) routing strategy in your SPA.

I have no ideas of how to fix this on ReDoc side at the moment. I will think about this. Maybe I'll find some solution.

For future travelers using HashRouter - my workaround was to disable location updates altogether by patching the MenuStore activate function. Navigation still works, you just don't get the url state:

import { RedocStandalone, MenuStore } from "redoc";

let originalActivate = MenuStore.prototype.activate;

MenuStore.prototype.activate = function(menuItem) {
  // Call activate() and pass through the menuItem, but set both `updateLocation` and `rewriteHistory` to false
  // https://github.com/Redocly/redoc/blob/42696a01ba8ef27523da40c07a5e61ba606e247f/src/services/MenuStore.ts#L197-L199
  originalActivate.apply(this, [menuItem, false, false]);
};

export default RedocStandalone;

Would love an option to disable the URL hash altogether

Moving it to a query string instead would also be nice, i.e. ?redocLocation=operation/CreateThing

For anyone else trying to deploy this on GitHub pages with something like react-router, you can try using https://github.com/rafgraph/spa-github-pages to make it so that you don't have to use HashRouter and you can get around this issue 馃槃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bmarwell picture bmarwell  路  3Comments

karussell picture karussell  路  3Comments

gauravmokhasi picture gauravmokhasi  路  4Comments

RamakrishnaChilaka picture RamakrishnaChilaka  路  3Comments

gavinkalika picture gavinkalika  路  3Comments