Motivation / Goals
Drupal redirects should work, not break the site by redirecting an API request to the frontend (thus serving html instead of the api request)
Example:* Redirect module is used to redirect /foo to /bar* Outcome: When I open a link /foo I'll endup on page /bar. Regardless of whether I use client side or server side navigation.
Currently the /foo request would be redirected to /bar - that shows the right content, but the site-visitors is not redirect to /bar. Insteads of redirecting the API request, the frontend must understand that the CMS wants to issue a redirect and follow that.
Solution
We introduce a new API key for sending "redirects" from the backend to the frontend in the lupus_ce_renderer response. When the new key "redirect" is set, all other keys may be omitted.
Backend code should be re-usable and go into the lupus_ce_renderer module, i.e. work with any module provide redirects - not just redirect module.
Frontend code should be re-usable and go into the nuxt drupal-ce module, so we can open a fitting PR there.
API data structure for redirects
# Redirect to Drupal-internal path
{ redirect: {
external: false,
statusCode: 301,
url: /some-path?with-query=1
}
# title, content, ... - can all be empty
}
# Redirect to external URL
{
redirect: {
external: true,
statusCode: 302,
url: https://www.google.com }
}
Original report.
Problem/Motivation
Currently, redirects are not handled in a special way in lupus_ce_renderer. That's fine for Drupal internal redirects, but creates troubles when Drupal tries to issue an off-site redirect.
The goal of an off-site redirect is to redirect the browser to the this page, not the api client. Since the API client won't get custom-elements returned, this will lead to errors if not handled specifically.
However, it's not possible to handle this in the client during client side navigation, e.g. see https://github.com/axios/axios/issues/932#issuecomment-307390761
Proposed resolution
Add explicit redirect support: When rendering into custom elements, detect off-site redirects and render them in a special way which clients may interpret.
We can simply do this by adding a 'redirect' key to the page response json object instead of content.
On the client, e.g. for Nuxt we can then use e.g. the nuxt-redirect after fetching the response
Issue fork lupus_ce_renderer-3188003
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
fagoupdated issue summary. we even need to do this for Drupal internal redirects when using SSR.
Comment #4
fagook implemented this, let's do some testing and develop the frontend changes now.
https://git.drupalcode.org/project/lupus_ce_renderer/-/merge_requests/6/...
Comment #6
fagohttps://github.com/drunomics/nuxt-module-drupal-ce/releases/tag/1.0.0-beta5 has the client-side changes implemented. This works great together, so let's merge and release this.
Comment #7
fago