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 4.0 Dev Release

Adonis4.0 has been much-awaited release for AdonisJs so far. The framework is full of new and fresh ideas to make you even more productive. The documentation for dev release is available at dev.adonisjs.com. The API is 100% final, so... Continue →