ura method

String ura (String iUrl, { bool includeSession })

URL Rewritten for an Attribute.

It is very common to rewrite an internal URL and then put its value into an attribute. For example,

var link = "~/foo?a=1&b=2";
resp.write('<a href="${HEsc.attr(req.rewriteUrl(link))}">here</a>');

This convenience method invokes both rewriteUrl and HEsc.attr so the above can be simply written as:

resp.write('<a href="${req.ura(link)}">here</a>');

If used for the method attribute of a HTML form element, set includeSession to false and use the Request.sessionHiddenInputElement method inside the form element. See Request.sessionHiddenInputElement for more details.

Implementation

String ura(String iUrl, {bool includeSession}) =>
    HEsc.attr(rewriteUrl(iUrl, includeSession: includeSession));