Return to v1.4.5 docs


Adds a new route to your application.

Name Type Required Default Description
name string No Name for the route. This is referenced as the name argument in functions based on URLFor() like linkTo(), startFormTag(), etc.
pattern string Yes The URL pattern that the route will match.
controller string No Controller to call when route matches (unless the controller name exists in the pattern).
action string No Action to call when route matches (unless the action name exists in the pattern).
<!--- Example 1: Adds a route which will invoke the `profile` action on the `user` controller with `params.userName` set when the URL matches the `pattern` argument --->
<cfset addRoute(name="userProfile", pattern="user/[username]", controller="user", action="profile")>

<!--- Example 2: Category/product URLs. Note the order of precedence is such that the more specific route should be defined first so Wheels will fall back to the less-specific version if it's not found --->
<cfset addRoute(name="product", pattern="products/[categorySlug]/[productSlug]", controller="products", action="product")>
<cfset addRoute(name="productCategory", pattern="products/[categorySlug]", controller="products", action="category")>
<cfset addRoute(name="products", pattern="products", controller="products", action="index")>

<!--- Example 3: Change the `home` route. This should be listed last because it is least specific --->
<cfset addRoute(name="home", pattern="", controller="main", action="index")>