lukeed / freshie

(WIP) A fresh take on building universal applications with support for pluggable frontends and backends.
MIT License
155 stars 2 forks source link

Redirects #4

Closed lukeed closed 4 years ago

lukeed commented 4 years ago

Should be as simple as modifying the context within a preload function:

export function preload(req, context) {
  context.redirect = 'https://new.location';
  context.status = 301; // 302 default
}

The trigger is the redirect key, not the status code value! Relative paths will be resolved from the current req.url.

Can be fulfilled on client-side too, except status change. This would use a history.replaceState when context.redirect exists.