{"id":24023807,"url":"https://github.com/beyondjs/routing","last_synced_at":"2026-06-15T19:31:03.252Z","repository":{"id":270973734,"uuid":"844295862","full_name":"beyondjs/routing","owner":"beyondjs","description":"A powerful client-side routing package for Beyond.js, supporting hash and pathname modes, with built-in history management and customizable navigation.","archived":false,"fork":false,"pushed_at":"2025-01-04T13:04:05.000Z","size":1296,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-11-18T19:06:21.093Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beyondjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-19T00:30:54.000Z","updated_at":"2025-01-04T13:04:09.000Z","dependencies_parsed_at":"2025-01-04T14:33:16.597Z","dependency_job_id":null,"html_url":"https://github.com/beyondjs/routing","commit_stats":null,"previous_names":["beyondjs/routing"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/beyondjs/routing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondjs%2Frouting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondjs%2Frouting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondjs%2Frouting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondjs%2Frouting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beyondjs","download_url":"https://codeload.github.com/beyondjs/routing/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondjs%2Frouting/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34377872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-15T02:00:07.085Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-08T14:44:43.193Z","updated_at":"2026-06-15T19:31:03.228Z","avatar_url":"https://github.com/beyondjs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Beyond.js Routing\n\nThe `beyond-js/routing` package is a versatile client-side routing solution designed for modern web applications. It\nhandles routing modes, URL management, navigation history, and more, all while providing seamless integration for\ndynamic web applications.\n\n## Features\n\n-   Supports both `Hash` and `Pathname` routing modes.\n-   Automatic handling of URI parsing, query strings, and navigation.\n-   Integration with the browser’s history API for smooth state management.\n-   Customizable redirection logic.\n-   Full event-driven architecture with support for custom events.\n\n## Installation\n\n```bash\nnpm install @beyond-js/routing\n```\n````\n\n## Usage\n\n### Basic Setup\n\n```typescript\nimport { routing } from '@beyond-js/routing';\n\n// Initialize routing\nrouting.setup();\n\n// Navigate programmatically\nrouting.pushState('/new-path');\n\n// Listen to routing changes\nrouting.on('change', () =\u003e {\n\tconsole.log('Route changed to:', routing.uri.pathname);\n});\n```\n\n### Routing Modes\n\nThe package supports two routing modes:\n\n1. **Hash Mode**: URLs are managed using the hash fragment (e.g., `http://example.com/#/path`).\n2. **Pathname Mode**: URLs are managed using the path portion (e.g., `http://example.com/path`).\n\nThe routing mode is automatically determined based on the environment and configuration.\n\n```typescript\n// Check the current routing mode\nif (routing.mode === RoutingMode.Hash) {\n\tconsole.log('Hash mode is active');\n}\n```\n\n### Programmatic Navigation\n\nYou can programmatically navigate within your application using `pushState` and `replaceState`.\n\n```typescript\n// Push a new state to the history\nrouting.pushState('/new-path', { someState: 'example' });\n\n// Replace the current state\nrouting.replaceState({ anotherState: 'example' }, 'New Title', '/another-path');\n```\n\n### Handling Redirects\n\nCustom redirection logic can be implemented by defining the `redirect` method.\n\n```typescript\nrouting.redirect = async uri =\u003e {\n\tif (uri.pathname === '/old-path') {\n\t\treturn '/new-path'; // Redirect to a new path\n\t}\n};\n```\n\n### Backward and Forward Navigation\n\nControl the browser history using `back` and `forward` methods.\n\n```typescript\nrouting.back(); // Go back in history\nrouting.forward(); // Go forward in history\n```\n\n## API Reference\n\n### Routing Class\n\n#### Properties\n\n-   `mode: RoutingMode`: The active routing mode (`Hash` or `Pathname`).\n-   `history: BeyondHistory`: An instance managing browser history.\n-   `uri: URI`: The current URI being managed by the router.\n\n#### Methods\n\n-   `setup()`: Initializes the routing system.\n-   `pushState(uri: string, state?: object)`: Pushes a new state to the history and updates the URL.\n-   `replaceState(state: object, title: string, uri?: string)`: Replaces the current state and URL.\n-   `back()`: Navigates backward in the history.\n-   `forward()`: Navigates forward in the history.\n\n#### Events\n\n-   `change`: Triggered whenever the route changes.\n\n### URI Class\n\nThe `URI` class provides an easy way to parse and interact with URLs.\n\n#### Properties\n\n-   `pathname: string`: The path part of the URI.\n-   `search: string`: The query string of the URI.\n-   `qs: QueryString`: A parsed map of query parameters.\n-   `hash: string | undefined`: The hash fragment of the URI.\n\n### BeyondHistory Class\n\nManages the history stack and handles the browser’s history API.\n\n#### Properties\n\n-   `current: string`: The current URI.\n-   `position: HistoryPosition`: The current position in the history stack.\n\n#### Methods\n\n-   `pushState(uri: string, state: any)`: Pushes a new state to the browser’s history.\n-   `replaceState(state: any, title: string, uri: string)`: Replaces the current state.\n-   `back()`: Moves back in history.\n-   `forward()`: Moves forward in history.\n\n## Example Project Structure\n\n```plaintext\nsrc/\n│\n├── routing.ts           # Main routing logic\n├── uri/\n│   └── uri.ts           # URI parser and query string handler\n└── history/\n    ├── history.ts       # Custom history manager\n    ├── position.ts      # Tracks the current position in history\n    └── records.ts       # Handles the history records\n```\n\n## Contributing\n\nContributions are welcome! Please submit a pull request or open an issue to discuss any changes.\n\n## License\n\nThis project is licensed under the MIT License.\n\n```\n\nThis README covers the core functionality and API of the routing package while maintaining clarity for developers looking to integrate it into their projects.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeyondjs%2Frouting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeyondjs%2Frouting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeyondjs%2Frouting/lists"}