pushState method
A handler that serves the file at the given path, unless the user has requested that path.
You can also limit this functionality to specific values of the Accept
header, ex. text/html
.
If accepts
is null
, OR at least one of the content types in accepts
is present,
the view will be served.
Implementation
RequestHandler pushState(String path, {Iterable? accepts}) {
var vPath = path.replaceAll(_straySlashes, '');
if (_prefix.isNotEmpty == true) vPath = '$_prefix/$vPath';
return (RequestContext req, ResponseContext res) {
var path = req.path.replaceAll(_straySlashes, '');
if (path == vPath) return Future<bool>.value(true);
if (accepts?.isNotEmpty == true) {
if (!accepts!.any((x) => req.accepts(x, strict: true))) {
return Future<bool>.value(true);
}
}
return servePath(vPath, req, res);
};
}