Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.

Conversation

@Phinart98
Copy link

Refactored the code to dynamically get the admin
index URL by leveraging the json_script templates tag.

Phinart98 and others added 2 commits March 23, 2025 02:06
Refactored the code to dynamically get the admin
index URL by leveraging the json_script templates tag.
Comment on lines 17 to 23
if (adminIndexElement) {
const adminIndexUrl = JSON.parse(adminIndexElement.textContent);
document.location.href = adminIndexUrl;
} else {
// Fallback to default if element not found
document.location.href = "/admin/";
}
Copy link
Owner

Choose a reason for hiding this comment

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

I don't really see a point to the conditional, it will always be true.

I also don't know if it's needed to use JSON.parse() or not. Maybe it is, but I feel like it's just a string so it isn't really doing anything.

Copy link
Author

Choose a reason for hiding this comment

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

I used JSON.parse() because it was used in the example shared in the documentation. I will read more on it to see if it's really needed in this situation.

Phinart98 and others added 2 commits March 26, 2025 00:09
Removed unnecessary conditional check for element existence since it will
always be present in the template.
Kept JSON.parse() as it's necessary when using json_script because the
template tag serializes values to JSON format, wrapping even simple strings
in quotes. Without it, navigation would fail due to the browser attempting
to navigate to a URL with quotation marks.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants