The following three constraints apply to route names. They will only work with
<LiquidOutlet />
because only
<LiquidOutlet />
has visibility into routes. (The other helpers like
<LiquidIf />
) don't know anything about routes.)
Each of them accepts one argument. The argument can be a string route name, a function that tests route names, or a list of either of those.
The next three constraint apply to routes' models. They too only
work with
<LiquidOutlet />
.
Each of them accepts a function for testing the model, which
receives the model as its first argument and should return a
boolean. You have optional access to the
other
model in the
second argument (that is, a
fromModel
matcher receives
(oldModel, newModel)
and a
toModel
matcher receives
(newModel, oldModel)
).
Examples:
// Matches any transition that ends up in the route named 'foo', no
// matter where it came from.
this.transition(this.toRoute('foo'), this.use('toLeft'));
// This is equivalent to the previous example, but showing a more
// generic form that lets you provide an arbitrary test.
this.transition(
this.toRoute(function (routeName) {
return routeName === 'foo';
}),
this.use('toLeft'),
);
// You can list multiple routes, and the constraint will be satisfied
// by any of them. This will match any transition that ends up in 'foo'
// or 'bar'.
this.transition(this.toRoute(['foo', 'bar']), this.use('toLeft'));
// You can mix and match strings and functions. This is equivalent to
// the previous example.
this.transition(
this.toRoute([
'foo',
function (routeName) {
return routeName === 'bar';
},
]),
this.use('toLeft'),
);
// All of these examples apply to fromRoute too. This will match any
// transition from 'foo' to 'bar', or from 'foo' to any route name
// starting with 'q'.
this.transition(
this.fromRoute('foo'),
this.toRoute([
'bar',
function (routeName) {
return /^q/.test(routeName);
},
]),
this.use('toLeft'),
);
// withinRoute is just a shorthand. Instead of saying this:
this.transition(this.fromRoute('foo'), this.toRoute('foo'), this.use('toLeft'));
// you can say this:
this.transition(this.withinRoute('foo'), this.use('toLeft'));
In case, you need to animate subroute transitions for a nested UI and you don't have an "index" route or template defined:
<header></header>
<sidebar><LiquidOutlet /></sidebar>
<h1>Edit</h1>
You can write a rule for an empty outlet, as follows:
this.transition(
this.fromRoute(null),
this.toRoute('main-route.edit'),
this.use('toUp'),
);