- Source:
Methods
redirect(urlopt, paramsopt, nullable, anchoropt, nullable, targetopt, nullable, postParamsopt, nullable, markListParamsopt, nullable)
Everything you need to do basic navigation without history API.
Provide a URL to navigate to or leave the URL out, to use the current full URL. See urlHref
for details.
Add GET-parameters (adding to those already present in the URL), define an anchor (or automatically get the one defined in the URL), set a target to define a window to navigate to (or open a new one) and even define POST-parameters to navigate while providing POST-data.
Provided params have to be a flat plain object, with ordinal values or arrays of ordinal values on the first level.
Everything else will be stringified and url-encoded as is. Usually, parameters defined here add to present
parameters in the URL. To force-override present values, declare the param name with a "!" prefix
({'!presentparam' : 'new'}
).
If you define POST-params to navigate to a URL providing POST-data we internally build a custom form element, with type "post", filled with hidden fields adding the form data, which we submit to navigate to the action, which contains our url. Even the target carries over.
If you define a target window and therefore open a new tab/window this function adds "noopener,noreferrer" automatically if the origins do not match to increase security. If you need the opener, have a look at "openWindow", which gives you more manual control in that regard.
If you define a target and open an external URL, repeated calls to the same target will open multiple windows due to the security settings.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
url |
String | URL |
<optional> |
null | the location to load, if null current location is reloaded/used |
params |
Object |
<optional> <nullable> |
null | plain object of GET-parameters to add to the url |
anchor |
String |
<optional> <nullable> |
null | anchor/hash to set for called url, has precedence over URL hash |
target |
String |
<optional> <nullable> |
null | name of the window to perform the redirect to/in, use "_blank" to open a new window/tab |
postParams |
Object |
<optional> <nullable> |
null | plain object of postParameters to send with the redirect, solved with a hidden form |
markListParams |
Boolean |
<optional> <nullable> |
false | if true, params with more than one value will be marked with "[]" preceding the param name |
- Source:
- See:
-
- Urls.urlHref
Throws:
error if url is not usable
Example
redirect('https://test.com', {search : 'kittens', order : 'asc'}, 'fluffykittens');
redirect(null, {order : 'desc'});