{"id":31956342,"url":"https://github.com/profullstack/enhanced-router","last_synced_at":"2026-03-08T05:32:04.499Z","repository":{"id":292681411,"uuid":"981597257","full_name":"profullstack/enhanced-router","owner":"profullstack","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-18T14:32:52.000Z","size":81,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-23T19:52:02.655Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/profullstack.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-05-11T13:23:59.000Z","updated_at":"2025-05-18T14:32:55.000Z","dependencies_parsed_at":"2025-10-14T14:50:07.364Z","dependency_job_id":"1f6dae5a-591e-488a-8c03-d3d8da60a4c1","html_url":"https://github.com/profullstack/enhanced-router","commit_stats":null,"previous_names":["profullstack/enhanced-router"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/profullstack/enhanced-router","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profullstack%2Fenhanced-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profullstack%2Fenhanced-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profullstack%2Fenhanced-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profullstack%2Fenhanced-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/profullstack","download_url":"https://codeload.github.com/profullstack/enhanced-router/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profullstack%2Fenhanced-router/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30246724,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T00:58:18.660Z","status":"online","status_checked_at":"2026-03-08T02:00:06.215Z","response_time":56,"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-10-14T14:48:36.333Z","updated_at":"2026-03-08T05:32:04.423Z","avatar_url":"https://github.com/profullstack.png","language":"JavaScript","readme":"# @profullstack/enhanced-router\n\nAn enhanced SPA router with transition management, layout management, and i18n integration. Built on top of [@profullstack/spa-router](https://github.com/profullstack/spa-router).\n\n## Features\n\n- **Layout Management**: Apply consistent layouts to your routes\n- **Transition Effects**: Smooth transitions between routes with proper cleanup\n- **i18n Integration**: Seamless integration with internationalization\n- **Middleware Support**: Add custom middleware for authentication, logging, etc.\n- **Error Handling**: Customizable error pages with layout support\n\n## Installation\n\n```bash\nnpm install @profullstack/enhanced-router\n```\n\n## Basic Usage\n\n```javascript\nimport { createRouter } from '@profullstack/enhanced-router';\n\n// Create the router\nconst router = createRouter({\n  rootElement: '#app',\n  transition: {\n    type: 'fade',\n    duration: 300\n  }\n});\n\n// Define routes\nconst routes = {\n  '/': {\n    view: () =\u003e '\u003ch1\u003eHome\u003c/h1\u003e\u003cp\u003eWelcome to the home page\u003c/p\u003e',\n    layout: 'default'\n  },\n  '/about': {\n    view: () =\u003e '\u003ch1\u003eAbout\u003c/h1\u003e\u003cp\u003eThis is the about page\u003c/p\u003e',\n    layout: 'default'\n  },\n  '/contact': {\n    view: () =\u003e '\u003ch1\u003eContact\u003c/h1\u003e\u003cp\u003eThis is the contact page\u003c/p\u003e',\n    layout: 'minimal'\n  }\n};\n\n// Register routes\nrouter.registerRoutes(routes);\n\n// Initialize the router\nrouter.init();\n```\n\n## API Reference\n\n### Creating a Router\n\n```javascript\nimport { createRouter } from '@profullstack/enhanced-router';\n\nconst router = createRouter({\n  // Root element selector (required)\n  rootElement: '#app',\n  \n  // Transition options (optional)\n  transition: {\n    type: 'fade', // 'fade', 'slide', or 'none'\n    duration: 300, // Duration in milliseconds\n    easing: 'ease', // CSS easing function\n    preventClicks: true // Prevent clicks during transition\n  },\n  \n  // Layout options (optional)\n  layouts: {\n    // Custom layouts\n    custom: content =\u003e {\n      // Create and return a DocumentFragment with the content\n    }\n  },\n  \n  // i18n options (optional)\n  i18n: {\n    localizer: myLocalizer, // Your localizer object\n    defaultLanguage: 'en',\n    languages: ['en', 'fr', 'es'],\n    rtlLanguages: ['ar', 'he']\n  },\n  \n  // Other options\n  disableAutoInit: false, // Disable auto-initialization\n  errorHandler: (path, error) =\u003e {\n    // Custom error handler\n  }\n});\n```\n\n### Defining Routes\n\n```javascript\nconst routes = {\n  '/': {\n    // View function that returns HTML string, DocumentFragment, or Node\n    view: () =\u003e '\u003ch1\u003eHome\u003c/h1\u003e',\n    \n    // Layout to use (optional, defaults to 'default')\n    layout: 'default',\n    \n    // Before enter hook (optional)\n    beforeEnter: (to, from, next) =\u003e {\n      // Check authentication, etc.\n      next(); // Continue to the route\n      // Or redirect: next('/login');\n    },\n    \n    // After render hook (optional)\n    afterRender: () =\u003e {\n      // Initialize components, etc.\n    }\n  },\n  \n  // Dynamic route parameters\n  '/users/:id': {\n    view: (params) =\u003e `\u003ch1\u003eUser ${params.id}\u003c/h1\u003e`,\n    layout: 'default'\n  }\n};\n\n// Register routes\nrouter.registerRoutes(routes);\n```\n\n### Navigation\n\n```javascript\n// Navigate to a path\nrouter.navigate('/about');\n\n// Navigate with options\nrouter.navigate('/users/123', {\n  replace: true, // Replace current history entry\n  data: { foo: 'bar' } // Custom data to pass to the route\n});\n```\n\n### Middleware\n\n```javascript\n// Add middleware\nrouter.use((to, from, next) =\u003e {\n  // Log navigation\n  console.log(`Navigating from ${from} to ${to.path}`);\n  \n  // Continue to the next middleware or route\n  next();\n  \n  // Or redirect\n  // next('/login');\n});\n```\n\n## Layout Management\n\nThe enhanced router provides a powerful layout management system that allows you to apply consistent layouts to your routes.\n\n### Default Layouts\n\nThe router comes with three default layouts:\n\n- `default`: Standard layout with header, content, and footer\n- `minimal`: Minimal layout with just the content\n- `error`: Error layout for error pages\n\n### Custom Layouts\n\nYou can define custom layouts when creating the router:\n\n```javascript\nconst router = createRouter({\n  layouts: {\n    custom: content =\u003e {\n      // Create a document fragment with the custom layout\n      const fragment = document.createDocumentFragment();\n      \n      // Create header\n      const header = document.createElement('header');\n      header.className = 'custom-header';\n      fragment.appendChild(header);\n      \n      // Create content container\n      const contentDiv = document.createElement('main');\n      contentDiv.className = 'custom-content';\n      \n      // Add the content\n      if (typeof content === 'string') {\n        const range = document.createRange();\n        const parsedContent = range.createContextualFragment(content);\n        contentDiv.appendChild(parsedContent);\n      } else if (content instanceof DocumentFragment) {\n        contentDiv.appendChild(content);\n      } else if (content instanceof Node) {\n        contentDiv.appendChild(content);\n      }\n      \n      fragment.appendChild(contentDiv);\n      \n      // Create footer\n      const footer = document.createElement('footer');\n      footer.className = 'custom-footer';\n      fragment.appendChild(footer);\n      \n      return fragment;\n    }\n  }\n});\n```\n\nYou can also register layouts after creating the router:\n\n```javascript\nrouter.getLayoutManager().registerLayout('dashboard', content =\u003e {\n  // Create and return a DocumentFragment with the content\n});\n```\n\n### Using Layouts in Routes\n\n```javascript\nconst routes = {\n  '/': {\n    view: () =\u003e '\u003ch1\u003eHome\u003c/h1\u003e',\n    layout: 'default' // Use the default layout\n  },\n  '/dashboard': {\n    view: () =\u003e '\u003ch1\u003eDashboard\u003c/h1\u003e',\n    layout: 'dashboard' // Use the dashboard layout\n  }\n};\n```\n\n## Transition Effects\n\nThe enhanced router provides smooth transition effects between routes.\n\n### Built-in Transitions\n\n- `fade`: Fade out the old content and fade in the new content\n- `slide`: Slide out the old content to the left and slide in the new content from the right\n- `none`: No transition effect\n\n### Custom Transitions\n\nYou can define custom transitions:\n\n```javascript\nimport { createTransitions } from '@profullstack/enhanced-router';\n\nconst customTransition = (fromEl, toEl) =\u003e {\n  return new Promise(resolve =\u003e {\n    // Implement your custom transition\n    // ...\n    \n    // Resolve the promise when the transition is complete\n    setTimeout(resolve, 500);\n  });\n};\n\nconst router = createRouter({\n  transition: {\n    transition: customTransition\n  }\n});\n```\n\n## i18n Integration\n\nThe enhanced router provides seamless integration with internationalization.\n\n### Basic Integration\n\n```javascript\nconst router = createRouter({\n  i18n: {\n    localizer: myLocalizer, // Your localizer object\n    defaultLanguage: 'en',\n    languages: ['en', 'fr', 'es'],\n    rtlLanguages: ['ar', 'he']\n  }\n});\n```\n\n### Using i18n in Routes\n\n```javascript\nconst routes = {\n  '/': {\n    view: () =\u003e {\n      const content = document.createDocumentFragment();\n      \n      const heading = document.createElement('h1');\n      heading.textContent = 'Home';\n      heading.setAttribute('data-i18n', 'home.title');\n      content.appendChild(heading);\n      \n      const paragraph = document.createElement('p');\n      paragraph.textContent = 'Welcome to the home page';\n      paragraph.setAttribute('data-i18n', 'home.welcome');\n      content.appendChild(paragraph);\n      \n      return content;\n    }\n  }\n};\n```\n\n## Examples\n\nSee the [examples](./examples) directory for complete usage examples.\n\n## License\n\nMIT","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprofullstack%2Fenhanced-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprofullstack%2Fenhanced-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprofullstack%2Fenhanced-router/lists"}