mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-09-18 09:29:24 +00:00
Forward and back works without rerendering
This commit is contained in:
parent
cd6652a48d
commit
2cada1697c
@ -227,7 +227,7 @@ export function ToolWorkflowProvider({ children }: ToolWorkflowProviderProps) {
|
||||
useNavigationUrlSync(
|
||||
navigationState.selectedTool,
|
||||
handleToolSelect,
|
||||
() => actions.setSelectedTool(null),
|
||||
handleBackToTools,
|
||||
toolRegistry,
|
||||
true
|
||||
);
|
||||
|
@ -38,11 +38,11 @@ export function useNavigationUrlSync(
|
||||
if (!enableSync) return;
|
||||
|
||||
if (selectedTool) {
|
||||
updateToolRoute(selectedTool, registry);
|
||||
updateToolRoute(selectedTool, registry, false); // Use pushState for user navigation
|
||||
} else {
|
||||
// Only clear URL if we're not on the home page already
|
||||
if (window.location.pathname !== '/') {
|
||||
clearToolRoute();
|
||||
clearToolRoute(false); // Use pushState for user navigation
|
||||
}
|
||||
}
|
||||
}, [selectedTool, registry, enableSync]);
|
||||
|
@ -48,14 +48,18 @@ export function parseToolRoute(registry: ToolRegistry): ToolRoute {
|
||||
/**
|
||||
* Update URL and fire analytics pixel
|
||||
*/
|
||||
function updateUrl(newPath: string, searchParams: URLSearchParams): void {
|
||||
function updateUrl(newPath: string, searchParams: URLSearchParams, replace: boolean = false): void {
|
||||
const currentPath = window.location.pathname;
|
||||
const queryString = searchParams.toString();
|
||||
const fullUrl = newPath + (queryString ? `?${queryString}` : '');
|
||||
|
||||
// Only update URL and fire pixel if something actually changed
|
||||
if (currentPath !== newPath || window.location.search !== (queryString ? `?${queryString}` : '')) {
|
||||
if (replace) {
|
||||
window.history.replaceState(null, '', fullUrl);
|
||||
} else {
|
||||
window.history.pushState(null, '', fullUrl);
|
||||
}
|
||||
firePixel(newPath);
|
||||
}
|
||||
}
|
||||
@ -63,7 +67,7 @@ function updateUrl(newPath: string, searchParams: URLSearchParams): void {
|
||||
/**
|
||||
* Update the URL to reflect the current tool selection
|
||||
*/
|
||||
export function updateToolRoute(toolId: ToolId, registry: ToolRegistry): void {
|
||||
export function updateToolRoute(toolId: ToolId, registry: ToolRegistry, replace: boolean = false): void {
|
||||
const tool = registry[toolId];
|
||||
if (!tool) {
|
||||
console.warn(`Tool ${toolId} not found in registry`);
|
||||
@ -76,17 +80,17 @@ export function updateToolRoute(toolId: ToolId, registry: ToolRegistry): void {
|
||||
// Remove tool query parameter since we're using path-based routing
|
||||
searchParams.delete('tool');
|
||||
|
||||
updateUrl(newPath, searchParams);
|
||||
updateUrl(newPath, searchParams, replace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear tool routing and return to home page
|
||||
*/
|
||||
export function clearToolRoute(): void {
|
||||
export function clearToolRoute(replace: boolean = false): void {
|
||||
const searchParams = new URLSearchParams(window.location.search);
|
||||
searchParams.delete('tool');
|
||||
|
||||
updateUrl('/', searchParams);
|
||||
updateUrl('/', searchParams, replace);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user