Routing Namespaces
You can create a-la-carte namespaces for URL routes. Namespaces are cool groupings of routes according to a specific URL entry point. So you can say that all URLs that start with /testing will be found in the testing namespace and it will iterate through the namespace routes until it matches one of them.
Much how modules work, where you have a module entry point, you can create virtual entry point to ANY route by namespacing it. This route can be a module a non-module, package, or whatever you like. You start off by registering the namespace using the addNamespace( pattern, namespace ) method or the fluent route().toNamespaceRouting() method.
1
addNamespace( pattern="/testing", namespace="test" );
2
route( "/testing" ).toNamespaceRouting( "test" );
3
4
addNamespace( pattern="/news", namespace="blog" );
5
route( "/news" ).toNamespaceRouting( "blog" );
Copied!
Once you declare the namespace you can use the grouping functionality to declare all the namespace routes or you can use a route().withNamespace() combination.
1
// Via Grouping
2
route( "/news" ).toNamespaceRouting( "blog" )
3
.group( { namespace = "blog" }, function(){
4
route( "/", "blog.index" )
5
.route( "/:year-numeric?/:month-numeric?/:day-numeric?", "blog.archives" );
6
} );
7
8
9
// Via Routing DSL
10
addNamespace( "/news", "blog" );
11
12
route( "/" )
13
.withNameSpace( "blog" )
14
.to( "blog.index" );
15
16
route( "/:year-numeric?/:month-numeric?/:day-numeric?" )
17
.withNameSpace( "blog" )
18
.to( "blog.archives" );
19
Copied!
Hint You can also register multiple URL patterns that point to the same namespace
Last modified 3yr ago
Copy link
Edit on GitHub