Redirect a user to a default page on sign-in

You can configure a Power Pages site to redirect a user to a default page after the user signs in.

To achieve this, you replace the default studio template that's used as the page layout for the home page. You replace this default template with a custom template that includes JavaScript code to redirect the user to the page of your choosing. The steps are:

  1. Make a copy of the default studio template web template.
  2. Add JavaScript code to the web template copy.
  3. Create a corresponding page template.
  4. Modify the home page to use the modified template.

Make a copy of the default studio template

  1. Open the Portal Management app, go to Web Templates, and open the Default studio template.

  2. Copy all of the content that follows the <!-- Default studio template. Please do not modify --> line.

    Copying the default studio template.

  3. Select New to create a new web template record.

  4. Give the template a name (for example, Home page template), and select the Website where you want to implement the redirect functionality. Paste the content from the default studio template, and then select Save.

Add JavaScript code

  1. In the new template, add the following JavaScript code. Replace ./page/ with the partial URL of the page you want to direct the user to:

    {% if user %}
    //if any user logs in
    {% else %}
    //Home webpage code, if you don't want to display the page when the user is being redirected
    {% endif %}
    //Home webpage code, if you want to display the page when the user is being redirected

    New web template with JavaScript added.

  2. Select Save.

Create a page template

  1. In the Portal Management app, select Page templates.

  2. Select New, and then create a new page template record.

  3. Give the page template a name (for example, Home page template). Select the Website record where you want to have the functionality, choose the Type as Web Template, and select the Web Template you created in the previous step.

    Creating a new page template.

Update the home page

  1. Go to the Portal Management app.

  2. In Web Pages, locate the Home webpage record. Change the Page Template to the page template record you created earlier. Select Save & Close.

    Update the home page.

Now, when a user signs in, they'll be redirected to the page you specified in the JavaScript code in the updated web template.

See also