diff --git a/src/runtime-showcase/components/standalone-provider/standalone-provider.tsx b/src/runtime-showcase/components/standalone-provider/standalone-provider.tsx index d176f76..9ae6faf 100644 --- a/src/runtime-showcase/components/standalone-provider/standalone-provider.tsx +++ b/src/runtime-showcase/components/standalone-provider/standalone-provider.tsx @@ -94,6 +94,7 @@ export function StandaloneProvider(props: StandaloneProviderProps): ReactNode { const initialDefaultStory = useInitial(defaultStory); useEffect(() => { + const disconnect = initialRouter.connect(); const currentStoryPathname = initialRouting.getStoryPathname(initialRouter.getLocation()); const navigateToDefault = () => { @@ -116,7 +117,7 @@ export function StandaloneProvider(props: StandaloneProviderProps): ReactNode { } } - return initialRouter.connect(); + return disconnect; }, [ // stable: initialRouter, diff --git a/src/runtime-showcase/utils/routing.ts b/src/runtime-showcase/utils/routing.ts index 6ae9fda..e406928 100644 --- a/src/runtime-showcase/utils/routing.ts +++ b/src/runtime-showcase/utils/routing.ts @@ -17,10 +17,13 @@ function addBasePath(base: string, path: string): string { } function removeBasePath(base: string, path: string): string { - // @todo не уверен но вроде можно url.href.replace(baseUrl.href, '') но если путь "/" то не работает const url = new URL(path, new URL(base, 'http://stub.com')); - return `/${url.pathname.replace(base, '').replace(/^\//, '')}`; + return `${url.pathname.replace(base, '')}${url.hash}${url.search}`; +} + +function formatStoryPathname(path: string): string { + return `/${path.replace(/^\//, '').replace(/\/$/, '')}`; } export class PathnameRouting implements ShowcaseRouting { @@ -31,13 +34,13 @@ export class PathnameRouting implements ShowcaseRouting { } getStoryPathname(location: RouterLocation) { - const result = location.pathname.replace(/\/$/, ''); + const result = `${location.pathname.replace(/\/$/, '')}/`; if (this.publicPath) { - return removeBasePath(this.publicPath, result); + return formatStoryPathname(removeBasePath(this.publicPath, result)); } - return result; + return formatStoryPathname(result); } getStoryShowcaseUrl(story: StoryModule): string {