Try Install Learn Blog API Packages GitHub
Pages

Routing

In Mint, routes of an application are defined at the top level with the routes block.

Here is an example of an application where you can list users on one route and show a single user on another route:

routes {
  / {
    Application.setPage("index")
  }

  /users/:id (id: Number) {
    Application.setPage("show")
    Application.loadUser(id)
  }
}

Keep in mind the following things:

  • Routes are matched in the order they are defined from top to bottom
  • Routes can only have one routes block per application
  • Routes are used to set the state, not to render things

Matching parameters

You can use URL parameters to match on varied routes.

Parameters are typed checked and if it can't convert the String into the desired type it means that the route will not be matched.

This is an example of matching blog posts:

routes {
  /blog {
    Application.setPage("blog")
  }

  /blog/:slug (slug: String) {
    Application.setPage("post")
    Application.loadPost(slug)
  }
}

Matching everything

You can use the * to match every not matched route.

The position of the route does not matter, it will be matched after every other route.

routes {
  / {
    Application.setPage("index")
  }

  * {
    Application.setPage("not_found")
  }
}