Skip to content

chore: #ENABLING-567 redirect old path before rendering - #8

Merged
Romu-C merged 1 commit into
mainfrom
feat/ENABLING-567_redirect-old-path-before-rendering
Dec 22, 2025
Merged

Romu-C merged 1 commit into
mainfrom
feat/ENABLING-567_redirect-old-path-before-rendering

Conversation

@Romu-C

@Romu-C Romu-C commented Dec 16, 2025

Copy link
Copy Markdown
Contributor

Description

This PR refactors the URL redirection logic for handling old hash-based routes by moving it from the root route loader to the router initialization phase. This ensures redirections occur before the router is created rather than during route loading.

Key Changes:

  • Extracted redirection logic into a dedicated manageRedirections function in a new redirections module
  • Moved redirection execution from route loader to router creation in routes/index.tsx
  • Changed from location.replace() to window.history.replaceState() for smoother navigation

Type of change

Please check options that are relevant.

  • Chore (PATCH)
  • Doc (PATCH)
  • Bug fix (PATCH)
  • New feature (MINOR)
  • Breaking change (MAJOR)

PATCH: refactor, internal or non-breaking change which fixes an issue

MINOR: non-breaking change which adds functionality

MAJOR: fix or feature that would cause existing functionality to not work as expected

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the URL redirection logic for handling old hash-based routes by moving it from the root route loader to the router initialization phase. This ensures redirections occur before the router is created rather than during route loading.

Key Changes:

  • Extracted redirection logic into a dedicated manageRedirections function in a new redirections module
  • Moved redirection execution from route loader to router creation in routes/index.tsx
  • Changed from location.replace() to window.history.replaceState() for smoother navigation

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
frontend/src/routes/root/index.tsx Removed URL redirection logic and unused imports from the root route loader
frontend/src/routes/redirections/index.tsx Added new module with manageRedirections function to check and return redirect paths for old hash-based URLs
frontend/src/routes/index.tsx Integrated manageRedirections to handle URL redirections before router creation using window.history.replaceState

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +8 to +16
let redirectPath = '';
const isPath = matchPath('/view/:id', hashLocation);

if (isPath) {
// Redirect to the new format
redirectPath = `/id/${isPath?.params.id}`;
}

return redirectPath;

Copilot AI Dec 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When hashLocation exists but doesn't match the pattern (isPath is falsy), this function returns an empty string instead of null. This is inconsistent with the documented return type and could cause unexpected behavior in the calling code where an empty string is truthy. The function should return null when no redirection is needed, regardless of whether a hash exists.

Suggested change
let redirectPath = '';
const isPath = matchPath('/view/:id', hashLocation);
if (isPath) {
// Redirect to the new format
redirectPath = `/id/${isPath?.params.id}`;
}
return redirectPath;
const isPath = matchPath('/view/:id', hashLocation);
if (isPath) {
// Redirect to the new format
return `/id/${isPath?.params.id}`;
}
// No redirection needed for this hash
return null;

Copilot uses AI. Check for mistakes.

if (isPath) {
// Redirect to the new format
redirectPath = `/id/${isPath?.params.id}`;

Copilot AI Dec 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The optional chaining operator is redundant here since the code is already inside an if statement that checks isPath is truthy. This can be simplified to isPath.params.id for better clarity and consistency.

Suggested change
redirectPath = `/id/${isPath?.params.id}`;
redirectPath = `/id/${isPath.params.id}`;

Copilot uses AI. Check for mistakes.
@Romu-C
Romu-C merged commit 9f3957e into main Dec 22, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants