Changing Route.url behavior

The Route.url method returns a fully qualified URL to a registered route. For example:

// register route
Route.get('user/:username', 'UserController.show')

// following returns - user/virk
Route.url('user/:username', { username: 'virk' })

// or resolve using controller.method name
Route.url('UserController.show', { username: 'virk' })

For a specific domain #

Route.url method used to take a 3rd parameter called domain. Which resolves the URL but registered under a specific domain.

Route
  .get('post/:slug', 'PostController.show')
  .domain('blog.adonisjs.com')

// following returns - http://blog.adonisjs.com/post/adonis-101
Route.url(
  'PostController.show',
  { slug: 'adonis-101' },
  'blog.adonisjs.com'
)

In near future #

Going forward the 3rd parameter needs to be an object over a string. The change is done in the favor of accepting more configuration options in the near future.

Route.url(
  'PostController.show',
  { slug: 'adonis-101' },
  { domain: 'blog.adonisjs.com' }
)
 
48
Kudos
 
48
Kudos

Now read this

Adonis 3.0 dev release

Adonis 3.0 is going to be the most stable release so far. In past few months, we have gathered plenty of feedback, solved a handful of issues and progressively made Adonis the most practical framework in the community. The newer version... Continue →