Skip to content

[Bug]: Form action path does not take basename into account #9416

@nemjit001

Description

@nemjit001

What version of React Router are you using?

6.4.1

Steps to Reproduce

Create a browser router with a basename, and add a route with an action and a form:

index.js:

const router = createBrowserRouter([
    {
        path: '/',
        element: <App />,
        action: action
    },
], { basename: 'foo' })

app.js:

function action({ params }) {
    console.log('foo')
}

function App() {
    return (<Form method='post'>
        <button type='submit'>submit</button>
    </Form>)
}

The form posts to '/' instead of 'foo/'

A work around is specifying the action path with the basename:

    { /* other code */ }
    <Form method='post' action ='foo/'>
        <button type='submit'>submit</button>
    </Form>
    { /* other code */}

Expected Behavior

The expected behaviour is that the basename will be added before the action url of the form (according to the docs this is the current path)

Actual Behavior

The actual behaviour is that the path to the route is evaluated without taking the basename into account.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions