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

Here you go - Adonis 4.0 ?

Version 4.0 of AdonisJs is officially out and not only it is ready to be used in production, but you can also invest your time to build long-term projects, and there are reasons behind such a strong voice. Javascript as a language has... Continue →