route-hook.ts


Overview

The route-hook.ts file provides a collection of React hooks tailored for managing and interacting with URL routes and query parameters within a React application that uses the umi routing framework. These hooks facilitate extracting specific segments of the URL path, retrieving and setting query parameters (notably for pagination and knowledge-related identifiers), and performing navigation with state management.

This file primarily aims to abstract and simplify common routing and query parameter operations related to a knowledge base or dataset context, enhancing code reuse and readability across the application.


Detailed Documentation

Enumerations

SegmentIndex

export enum SegmentIndex {
  Second = '2',
  Third = '3',
}

Hooks


useSegmentedPathName

export const useSegmentedPathName = (index: SegmentIndex) => string

useSecondPathName

export const useSecondPathName = () => string

useThirdPathName

export const useThirdPathName = () => string

useGetKnowledgeSearchParams

export const useGetKnowledgeSearchParams = () => {
  documentId: string;
  knowledgeId: string;
}

useNavigateWithFromState

export const useNavigateWithFromState = () => (path: string) => void

useNavigateToDataset

export const useNavigateToDataset = () => () => void

useGetPaginationParams

export const useGetPaginationParams = () => {
  page: string | number;
  size: string | number;
}

useSetPaginationParams

export const useSetPaginationParams = () => {
  setPaginationParams: (page?: number, pageSize?: number) => void;
  page: number;
  size: number;
}

Important Implementation Details and Algorithms


Interaction with Other Parts of the System


Visual Diagram

classDiagram
    class route-hook {
        <<hooks module>>
    }
    
    class SegmentIndex {
        <<enum>>
        +Second: '2'
        +Third: '3'
    }
    
    route-hook ..> SegmentIndex : uses
    
    route-hook : +useSegmentedPathName(index: SegmentIndex) : string
    route-hook : +useSecondPathName() : string
    route-hook : +useThirdPathName() : string
    route-hook : +useGetKnowledgeSearchParams() : {documentId: string, knowledgeId: string}
    route-hook : +useNavigateWithFromState() : (path: string) => void
    route-hook : +useNavigateToDataset() : () => void
    route-hook : +useGetPaginationParams() : {page: string | number, size: string | number}
    route-hook : +useSetPaginationParams() : {setPaginationParams: (page?: number, pageSize?: number) => void, page: number, size: number}

Summary

The route-hook.ts file is a utility module providing React hooks for streamlined access and management of URL paths and query parameters within a umi-based React application. It abstracts common routing logic related to knowledge management and pagination, enhancing developer productivity and maintaining consistency across the app's navigation and URL state handling.