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' }
)
 
47
Kudos
 
47
Kudos

Now read this

Contributing to AdonisJs

Quite often I am asked on how to contribute to AdonisJs and it is so important to have some clarity on same since contributors are the force behind any open source project. This post gives an overview on how you can get started... Continue →