Skip to content

digitalist-se/next_path_alias

Repository files navigation

Next.js Path Alias

Contents of this file

  • Introduction
  • Requirements
  • Installation
  • Usage
  • Limitations

Introduction

This module allows the re-use of the same path alias on multiple Drupal nodes within a decoupled multi-site configuration, where various frontend sites are controlled by a unique Drupal backend. Each path alias remains unique per Next.js frontend.

Requirements

Installation

  1. Execute the following Drush command:

    drush -y en next_path_alias
    
  2. Navigate to /admin/config/services/next/path-alias and designate the field in your content that identifies the associated Next.js site for the frontend.

  3. Head over to /admin/config/services/next/settings and choose Simple OAuth - Aliased URL instead of Simple OAuth.

Usage

You may likely be obtaining routing information within your Next.js application using:

  const path = await drupal.translatePathFromContext(context)

https://next-drupal.org/docs/pages#advanced-example

This query should be replaced by:

const pathFromContext = drupal.getPathFromContext(context);
const path = await drupal.translatePath(
    `${pathFromContext}?next-site=${process.env.DRUPAL_SITE_ID}`,
    {
      withAuth: true,
    },
);

Limitations

This module depends on the functionality provided by Pathauto for data storage. Only content with the option 'Generate automatic URL alias' enabled can share the same path alias.

One option to work around this limitation is to use an additional field for storing the path alias, and then configure URL alias patterns based on it.

About

For hosting the “Next.js Site Path Alias” module

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages