Routes
Startox Pilot is a JavaScript router designed for ease of use and flexibility. It employs regular expressions to offer dynamic routing, allowing for both straightforward and complex navigation paths.
Stratox Pilot can be used stand alone as a library.
As a universal library, it works across different platforms without needing any external dependencies. This independence makes Startox Pilot a practical option for developers in search of a dependable routing tool that combines advanced features and modular design in a compact package.
You find the router file at:
A really Basic example
And you can of course add multiple paths.
Using Regular Expressions
To incorporate regular expressions in routing patterns, enclose the expression within curly brackets: {PATTERN}
. This syntax allows for flexible and powerful URL matching based on specified patterns.
Binding Router Patterns to a Key
It is strongly advised to associate each URI path you wish to access with a specific key. This approach enhances the clarity and manageability of your route definitions.
You can also map an entire path to a key, allowing for more concise and organized route management.
Combining pattern with keywords
Combining patterns with keywords e.g. (post-[0-9]+) enables you to create more expressive and versatile route definitions.
Handling Unlimited Nested Paths
To accommodate an unlimited number of nested paths within your routing configuration, you can utilize the pattern ".+"
. However, it's strongly advised to precede such a router pattern with a specific prefix to maintain clarity and structure, as demonstrated in the example below with the prefix /shop
.
This approach allows for the dynamic handling of deeply nested routes under a common parent path, offering flexibility in how URLs are structured and processed.
Optional URI Paths
To define one or more optional URI paths, enclose the path segment (excluding the slash) in brackets followed by a question mark, for example: /(PATH_NAME)?. This syntax allows for flexibility in route matching by making certain path segments non-mandatory.
It's important to note that you should not enclose the leading slash in brackets. The leading slash is automatically excluded from the pattern, ensuring the correct interpretation of the route.
Catch status errors
There is an optional and special router pattern that let's you catch HTTP Status Errors with in a router.
Last updated