Skip to main content

Overview

The getCleanUrl utility function creates a new URL with session name and password parameters removed. This is essential for cleaning up URLs when users leave sessions, creating shareable non-session URLs, or maintaining clean navigation history.
Perfect for: Session cleanup, URL normalization, leaving sessions, history management, and creating clean shareable URLs.

Import

Signature

Parameters

URL
required
The URL to clean by removing session parameters
string
default:"rtName"
The query parameter key to remove (session name)
string
default:"rtPwd"
The hash parameter key to remove (session password)

Returns

URL
A new URL instance without the specified session name and password parameters

Examples

Basic Usage

Remove default session parameters from a URL:

Custom Parameter Keys

Remove custom session parameter keys:

Leave Session Implementation

Clean URL when users leave a session:

URL History Management

Manage browser history with clean URLs:

Shareable URL Generator

Create clean URLs for sharing non-session content:

Router Integration

Integrate with React Router for clean navigation:

URL Sanitizer for Analytics

Clean URLs before sending to analytics:

Bookmark Manager

Create clean URLs for bookmarking:

Privacy Protection

Remove sensitive parameters for privacy:

Automatic URL Cleanup

Automatically clean URLs based on application state:

URL Structure

The function removes parameters following this pattern: Before cleaning:
After cleaning:
  • Query Parameters: Specified session name parameter is removed
  • Hash Parameters: Specified session password parameter is removed
  • Other Parameters: All other query and hash parameters are preserved

Best Practices

Session Cleanup

Privacy Protection

Browser History

Common Use Cases

  • Session Cleanup: Remove session parameters when users leave
  • URL Sharing: Create clean URLs for public sharing
  • Analytics: Send clean URLs to analytics services
  • Bookmarking: Save clean URLs for future access
  • Navigation: Maintain clean URL structure in application

TypeScript Support

The function is fully typed for better development experience: