Search code examples
coldfusionfw1

Starting slash in FW/1 route pattern matching


I am reviewing the configuration of FW/1. I notice that some of the routes start with a / and others don't. Is there any difference between the two?

variables.framework.routes = [
   { "chart/home"                           = "chart/home"},
   ...
   { "/location/home"                       = "location/home"},

Solution

  • Have you noticed any difference in behavior from the two? I don't think there is a difference. From the documentation and examples that I could find they are all preceded by a /. I presume that FW/1 is allowing both but they work the same.

    Snippet from the documentation here - http://framework-one.github.io/documentation/developing-applications.html#url-routes:

    URL Routes

    In addition to the standard /section/item and /module:section/item URLs that FW/1 supports ...

    An example from farther down that page shows the standard routes starting with a /:

    Here’s an example showing all the features together:

    variables.framework.routes = [
    { "/product/:id" = "/product/view/id/:id", "/user/{id:[0-9]+}" = "/user/view/id/:id",
      hint = "Display a specific product or user" },
    { "/products" = "/product/list", "/users" = "/user/list" },
    { "/old/url" = "302:/new/url" }
    

    ];

    Here is a link to the code that processes the routes you define - https://github.com/framework-one/fw1/blob/develop/framework/one.cfc#L1954-L2047

    In order to test this theory you could try the following.

    • Browse to www.yourdomain.com/location/home that should match the second route in your example.
    • Browse to www.yourdomain.com/chart/home that should match the first route in your example.
    • Browse to www.yourdomain.com/sometextchart/home does that match the first route in your example?
    • Browse to www.yourdomain.com/somefolder/chart/home does that match the first route in your example?
    • Browse to www.yourdomain.com/somefolder/sometextchart/home does that match the first route in your example?