routerino 2.3.4 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Routerino
2
2
 
3
- > A lightweight, SEO-optimized React router for modern websites and applications
3
+ > A lightweight, SEO-optimized React router & SSG for modern websites and applications
4
4
 
5
5
  For teams who want SPA simplicity with search-friendly static HTML, Open Graph previews, and **no framework lock-in.**
6
6
 
@@ -91,6 +91,7 @@ This simple configuration automatically handles routing, meta tags, and SEO opti
91
91
  - Enhanced User Experience
92
92
  - Support for sharing and social preview metadata
93
93
  - Snappy page transitions with automatic scroll reset, eliminating the jarring experience of landing mid-page when navigating
94
+ - Hash link support: SPA navigation to `/page#section` correctly scrolls to the target element, mimicking native browser behavior
94
95
 
95
96
  ## Installation
96
97
 
@@ -128,7 +129,18 @@ export const routes = [
128
129
  />;
129
130
  ```
130
131
 
131
- Links are just standard HTML anchor tags. No need to use special `<Link>` components—you can use whatever components or design system you like. For example: <a href="/some-page/">a link</a> is perfectly valid. This is very handy for markdown-based content. With standard link support in Routerino, you won't need to [transform your markdown content with custom React components](https://github.com/remarkjs/react-markdown?tab=readme-ov-file#appendix-b-components). Routerino handles same-origin anchor clicks. Cross-origin links and non-HTTP schemes (e.g., mailto:, tel:) are handled by the browser as usual.
132
+ Links are just standard HTML anchor tags. No need to use special `<Link>` components—you can use whatever components or design system you like. For example: <a href="/some-page/">a link</a> is perfectly valid. This is very handy for markdown-based content. With standard link support in Routerino, you won't need to [transform your markdown content with custom React components](https://github.com/remarkjs/react-markdown?tab=readme-ov-file#appendix-b-components).
133
+
134
+ Routerino handles same-origin anchor clicks via SPA navigation. The browser handles the rest natively, including:
135
+
136
+ - **Cross-origin links** (different domain)
137
+ - **Non-HTTP schemes** (mailto:, tel:, javascript:, etc.)
138
+ - **Modified clicks** (Ctrl/Cmd+click, Shift+click, Alt+click, right-click)
139
+ - **`target="_blank"`** links
140
+ - **`download`** attribute links
141
+ - **`rel="external"`** links
142
+ - **File extension links** — PDFs, ZIPs, images, fonts, videos, JSON, XML, and 50+ other file types are recognized automatically
143
+ - **Custom patterns** — use the [`ignorePatterns`](#ignorepatterns-string) prop for additional exclusions (e.g., `/api/`, `/legacy/`)
132
144
 
133
145
  ### Programmatic Navigation
134
146
 
@@ -223,6 +235,7 @@ All of these are optional, so it's easy to get started with nothing but a bare-b
223
235
  | [imageUrl](#imageurl-string) | string | Default image URL for sharing | `null` |
224
236
  | [touchIconUrl](#touchiconurl-string) | string | Image URL for PWA homescreen icon | `null` |
225
237
  | [debug](#debug-boolean) | boolean | Enable debug mode | `false` |
238
+ | [ignorePatterns](#ignorepatterns-string) | string[] | URL patterns to skip SPA routing | `[]` |
226
239
 
227
240
  ##### `title`: string;
228
241
 
@@ -299,7 +312,9 @@ Default: `false`
299
312
 
300
313
  ##### `baseUrl`: string;
301
314
 
302
- The base URL to use for canonical tags and og:url meta tags. If not provided, uses `window.location.origin`. This is useful when you want to specify the production URL regardless of the current environment.
315
+ The base URL to use for canonical tags and og:url meta tags. If not provided, uses `window.location.origin`.
316
+
317
+ This is useful when your site is accessible from multiple domains (for example, both example.com and example.net point to the same app). Set it to the preferred domain and all canonical and og:url tags will consistently point there. Also helpful for pinning to the production URL in development or staging environments.
303
318
 
304
319
  **Important:** The baseUrl must NOT end with a trailing slash (`/`). Correct example: `"https://example.com"`
305
320
 
@@ -337,6 +352,21 @@ Example debug output:
337
352
 
338
353
  Default: `false`
339
354
 
355
+ ##### `ignorePatterns`: string[];
356
+
357
+ An array of regex pattern strings to match against link hrefs. Any same-origin link matching one of these patterns will **not** be intercepted by the SPA router — the browser will handle the navigation natively instead.
358
+
359
+ Patterns are tested case-insensitively against the full resolved href (including origin).
360
+
361
+ ```jsx
362
+ // Skip API endpoints and a legacy section
363
+ <Routerino routes={routes} ignorePatterns={["/api/", "/admin/legacy/"]} />
364
+ ```
365
+
366
+ Routerino also has a built-in list of file extensions that are automatically skipped: `.pdf`, `.zip`, `.docx`, `.png`, `.jpg`, `.svg`, `.mp4`, `.json`, `.xml`, `.csv`, `.txt`, `.ico`, `.woff2`, `.woff`, `.ttf`, `.mp3`, `.wav`, `.epub`, `.map`, `.css`, `.js`, `.wasm`, and many more. The `ignorePatterns` prop is for additional custom patterns beyond these defaults.
367
+
368
+ Default: `[]`
369
+
340
370
  #### RouteConfig props
341
371
 
342
372
  There is a default RouteConfig that will be loaded if you don't specify any routes. The default route is a basic template that can confirm your app is working and routing is good to go.
@@ -401,6 +431,31 @@ An array of HeadTag objects that can be added to the route to manage meta tags,
401
431
 
402
432
  - `target` (string): The "target" attribute of the tag. Defines where to open the linked resource.
403
433
 
434
+ - `innerHTML` (string): Inner HTML content for tags that require a closing tag, such as `<script>` and `<style>`. When provided, the tag is rendered as `<tag attrs>innerHTML</tag>` instead of a self-closing element. This enables structured data (JSON-LD), inline CSS, and other tag-body content.
435
+
436
+ ##### Structured Data Example
437
+
438
+ ```jsx
439
+ {
440
+ path: "/about/",
441
+ element: <AboutPage />,
442
+ tags: [{
443
+ tag: "script",
444
+ type: "application/ld+json",
445
+ innerHTML: JSON.stringify({
446
+ "@context": "https://schema.org",
447
+ "@type": "BreadcrumbList",
448
+ itemListElement: [
449
+ { "@type": "ListItem", "position": 1, "name": "Home", "item": "https://example.com/" },
450
+ { "@type": "ListItem", "position": 2, "name": "About", "item": "https://example.com/about/" },
451
+ ],
452
+ }),
453
+ }],
454
+ }
455
+ ```
456
+
457
+ This works both at runtime (via `updateHeadTag`) and during static site generation (via the forge plugin).
458
+
404
459
  ### Using the `useRouterino` Hook
405
460
 
406
461
  The `useRouterino` hook provides access to router state from any child component. This is the primary way to access route information and update head tags dynamically.
@@ -716,6 +771,8 @@ With Prerender (SPA):
716
771
 
717
772
  You can override the default with `useTrailingSlash={false}` if you prefer URLs without trailing slashes. Either way, Routerino ensures search engines see consistent, canonical URLs.
718
773
 
774
+ **Multi-domain deployments**: If your site is served from multiple domains, set `baseUrl` to the preferred domain to keep all canonical and og:url tags pointing to one place. For example, `<Routerino baseUrl="https://example.com" routes={routes} />` ensures search engines see one canonical domain even when the same page is reachable at example.net.
775
+
719
776
  ### Sitemap Generation
720
777
 
721
778
  - Automate the creation of `sitemap.xml` and `robots.txt` during your build process with Routerino Forge.
@@ -807,11 +864,25 @@ This creates an engaging Twitter preview with a large image, title, and descript
807
864
  ### Additional SEO Considerations
808
865
 
809
866
  - Use semantic HTML elements in your components for better content structure.
810
- - Implement structured data (JSON-LD) where applicable to enhance rich snippets in search results.
867
+ - Implement structured data (JSON-LD) where applicable to enhance rich snippets in search results. Use the `innerHTML` property on a `<script type="application/ld+json">` head tag (see the [Structured Data Example](#structured-data-example) above).
811
868
  - Ensure your site is mobile-friendly and loads quickly for better search engine rankings.
812
869
 
813
870
  By following these practices, you'll improve your site's SEO performance and social media presence when using Routerino.
814
871
 
872
+ ### Hash Links
873
+
874
+ Routerino supports standard `<a href="/page#section">` links for SPA navigation. After React renders the new page, it finds the element with the matching `id` and scrolls it into view.
875
+
876
+ **Sticky headers**: If your site has a fixed header, use the CSS [`scroll-margin-top`](https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-margin-top) property to offset the scroll target so content isn't hidden behind the header:
877
+
878
+ ```css
879
+ [id] {
880
+ scroll-margin-top: 80px; /* match your header height */
881
+ }
882
+ ```
883
+
884
+ This works for SPA navigation, native browser hash navigation, and direct page loads — no extra props or router changes needed.
885
+
815
886
  ## Sitemap and robots.txt Generation
816
887
 
817
888
  When using Routerino Forge for static site generation, `sitemap.xml` and `robots.txt` files are automatically generated during the build process:
@@ -915,11 +986,11 @@ routerinoForge({
915
986
  - Smart sizing: Uses aspect-ratio only to prevent layout shift without forcing dimensions
916
987
  - Hides images initially with `opacity: 0` to prevent broken image icons during load
917
988
 
918
- **Note:** Image optimization requires `ffmpeg` to be installed. Without it, images work normally but without blur placeholders. Install with `brew install ffmpeg` (Mac), `apt install ffmpeg` (Ubuntu), or `choco install ffmpeg` (Windows).
989
+ **Note:** Image optimization requires `ffmpeg` to be installed on your system. Install with `brew install ffmpeg` (Mac), `apt install ffmpeg` (Debian/Ubuntu), or `choco install ffmpeg` (Windows). Without ffmpeg, the Image component still works but falls back to the original image without optimization. A warning is shown during build if ffmpeg is not found but Image components are used.
919
990
 
920
991
  ##### CI/CD Setup for Image Optimization
921
992
 
922
- To enable image optimization in your CI/CD pipeline, you need to install ffmpeg. Here are examples for the most common setups:
993
+ For CI/CD environments without ffmpeg pre-installed, you'll need to install it as part of your build process. Here are examples:
923
994
 
924
995
  ###### GitHub Actions
925
996