Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -116,7 +117,7 @@ export function StandaloneProvider(props: StandaloneProviderProps): ReactNode {
}
}

return initialRouter.connect();
return disconnect;
}, [
// stable:
initialRouter,
Expand Down
13 changes: 8 additions & 5 deletions src/runtime-showcase/utils/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down