Wayfinder examples

How routing works in Wayfinder

In Wayfinder, custom routes take priority over default routes. You can even overwrite default routes with custom routes, although this can become confusing.

The shorter your custom route is, the higher it should come. For example, if /foo came before /foo/var, and the URL used was example.com/foo/bar, you will never reach the /foo/bar route. You can overcome this by swapping the order in the app/conf/routes.php file.

Custom routes

URL Route Class Method Params
/ / Defined in app/conf/routes.php Optionally defined in app/conf/routes.php. Defaults to index() None passed, optionally defined in app/conf/routes.php
/foo /foo Defined in app/conf/routes.php Optionally defined in app/conf/routes.php. Defaults to index() None passed, optionally defined in app/conf/routes.php
/foo/bar /foo Defined in app/conf/routes.php Optionally defined in app/conf/routes.php. Defaults to index() Parameters optionally defined in app/conf/routes.php passed first, followed by bar
/foo/bar /foo/bar Defined in app/conf/routes.php Optionally defined in app/conf/routes.php. Defaults to index() None passed, optionally defined in app/conf/routes.php
/foo/bar/foobar /foo/bar Defined in app/conf/routes.php Optionally defined in app/conf/routes.php. Defaults to index() Parameters optionally defined in app/conf/routes.php passed first, followed by foobar
/foo/bar/foobar/barfoo /foo/bar Defined in app/conf/routes.php Optionally defined in app/conf/routes.php. Defaults to index() Parameters optionally defined in app/conf/routes.php passed first, followed by foobar and then barfoo
/foo/bar/foobar/barfoo /foo/bar Defined in app/conf/routes.php Optionally defined as a numeric value in app/conf/routes.php. For this example, the value is 2, but defaults to index() when not set Parameters optionally defined in app/conf/routes.php passed first, followed by foobar but barfoo treated as the method name

Default routes

If no custom route is found, then Wayfinder looks for a matching default route. It does this by looking in the app/controller folder for the relevant file and invokes the Class.

URL Class Method Params
/ Defined in app/conf/routes.php index() None
/foo Foo definied in app/controller/Foo.php index() None
/foo/bar Foo definied in app/controller/Foo.php bar() None
/foo/bar/foobar Foo definied in app/controller/Foo.php bar() foobar
/foo/bar/foobar/barfoo Foo definied in app/controller/Foo.php bar() foobar, then barfoo

More details on parameters

There are some things to be aware of when constructing URLs in your project.