Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.

Commit

Permalink
doc(router): Add route helper make query string. (#330)
Browse files Browse the repository at this point in the history
* Add route helper make query string.

* Update 01-Routing.adoc

add some information for creating a url with a query string.
  • Loading branch information
b0jia authored and RomainLanz committed Feb 22, 2019
1 parent 7a519ce commit da9fa82
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions 04-Basics/01-Routing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,34 @@ Route.get('posts/:id', closure).as('posts.show')
route('posts.show', { id: 1 })
----

`route` helpers also accept a optional parameters object as third argument, it will handle `protocol`, `domain` and `query` options:

[source, js]
----
route('posts.show', { id: 1 }, {
query: { foo: 'bar' }
});
// resulting in /post/1?foo=bar
// Without parameters:
route('auth.login', null, {
domain: 'auth.example.com',
protocol: 'https',
query: { redirect: '/dashboard' }
});
// resulting in https://auth.example.com/login?redirect=%2Fdashboard
----

The same rules apply for the view.

[source, html]
----
<a href="{{ route('posts.show', { id: 1 }, {query: { foo: 'bar' }}) }}">Show post</a>
// href="/post/1?foo=bar"
----

== Route Formats

Route formats open up a new way for link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation[content negotiation, window="_blank"], where you can accept the response format as part of the URL.
Expand Down

0 comments on commit da9fa82

Please sign in to comment.