Skip to content

Leading slash redirects not working for next server actions (but does work locally) #396

Closed
@citypaul

Description

@citypaul

I spent some time trying to figure out why a redirect from a server action wasn't working. What made this more difficult was the fact that it works just fine locally, but when I deploy it to AWS the redirect does not work if there's a leading slash.

Absolute URLs work just fine, and removing the leading slash makes it work.

I've reduced this down to literally just a redirect in the server action itself, and the issue seems consistent for me.

If you have a server action inside it with literally nothing more than:

import { redirect } from "next/navigation";

export const myServerAction = () => {
   redirect("/dashboard");
}

This doesn't work when deployed, but does locally.

But if I do:

import { redirect } from "next/navigation";

export const myServerAction = () => {
   redirect("dashboard");
}

It's working just fine.

I'm using SST 2.41.2. All routes are based on the app dir. I'm on next 14.1.4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions