我有一个 Angular 7 应用程序,在特定路线上,我正在加载启用了深度链接的 swagger-ui (3.22.1)。 每当我点击标签或操作时,它会将#/{tagName}/{operationId}
附加到应用程序的基本 URL 中,而不是将其附加到加载 swagger-ui 的路由。 如何使 swagger-ui 将标签/操作 ID 附加到加载它的路由,而不是附加到角度应用程序的基本 URL。
假设 Angular 应用程序托管在localhost:4500
和localhost:4500/swagger-ui
我正在加载启用了深度链接的 swagger-ui。 每当我单击标签或操作时,它会像http://localhost:4500/#/pet
一样将#/{tagName}/{operationId}
附加到localhost:4500
,而不是将其附加到加载 swagger-ui 的路由,即localhost:4500/swagger-ui
?
如何使 swagger-ui 将标签/操作 ID 附加到localhost:4500/swagger-ui
,例如localhost:4500/swagger-ui/#/pet
而不是http://localhost:4500/#/pet
?
招摇UI配置
import SwaggerUI from 'swagger-ui';
SwaggerUI({
url: 'http://petstore.swagger.io/v2/swagger.json',
dom_id: '#swagger-ui-container',
deepLinking: true,
presets: [SwaggerUI.presets.apis]
});
我认为这是一个带有 swagger-ui 的错误。请参阅未解决的问题 https://github.com/swagger-api/swagger-ui/issues/5811 您可以使用猴子补丁暂时修复它
const pushState = window.history.pushState
window.history.pushState = function (state, title, url) {
if (state === null && title === null && url.startsWith('#/')) {
url = window.location.pathname + url
}
pushState.apply(this, [state, title, url])
}