Redirect the visitor

This builds on the following intros:


Let’s see how to redirect a visitor, both when serving a request directly, and from a content app.

We are on the page /foo. Let’ change the type of our foo file to app-1 and create a .Request file in it with type sjs-3. Now we can write our own code to redirect the visitor. For example, let’s redirect visitors to the root page.

response.attrStr('location', '/')

Going to /foo, we are indeed redirected to the root page.

Option 2: let’s redirect from a content app. Actually, it works identically, I just wanted to show you anyway.

Let’s create a content app on Page 1.

content. In placeholder 1. Type app-1. Create an .Inline file. Type sjs-3. It shall return hello world. So far so good; now, let’s redirect the user intsead.

response.attrStr('location', '/')

Voila, it works.