Use \Phoenix\Script\PhoenixScript::phoenix(); load phoenix js and also includes router js.

Use PHP Print Routes

Use Router to print route to HTML.

<button type="button" onclick="'{{ $router->route('sakura', ['id' => 25]) }}')"></button>

The output

<button type="button" onclick="'/flower/sakura/25')"></button>

Use Phoenix JS Router

Add route settings in PHP

\Phoenix\Script\PhoenixScript::addRoute('sakura_save', $router->route('sakura', ['id' => 25]));

And get this route by Phoenix.Router:

<button type="button" onclick="'sakura_save'))"></button>

Get route in anywhere, for example, use it in ajax call:

    url: Phoenix.route('sakura_save'),
    data: data,

    // ...
}).done(function () {
    // ...

Add Query

Use second argument as URL query.

Phoenix.route('sakura_save', {id: 123}); // /sakura/save?id=1

This will be useful if you write an AJAX updater:

function updateItem(id, data) {
    Phoenix.route('sakura', {id: id}), 

State Control

Phoenix Router can help you control browser history state.

Push a new history:

  uri: '/article/view',
  title: 'Article Title',
  state: {...}

Replace a history:

  uri: '/article/view',
  title: 'Article Title',
  state: {...}

Get current history state:

var state = Phoenix.Router.state();

Other methods as window.history proxies:


If you found a typo or error, please help us improve this document.