WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Form submission triggers client-side navigation when basename is set #175

@DominikDSR

Description

@DominikDSR

When using React Router with a basename that ends with a trailing slash, submitting a form managed by remix-hook-form triggers a client-side navigation instead of correctly submitting the form to the action.

Removing the trailing slash from the basename (e.g. /app instead of /app/) resolves the issue, but this has further implications with the way vite handles the basepath. In my case it will break my SPA because vite cannot resolve paths to client build assets anymore.

As a current workaround i have patched this part in the handleSubmit function:

const action = e?.currentTarget?.action.replace(
  `${window.location.origin}${basename === "/" ? "" : basename}`,
  "",
);

by replacing the action string with a "/" instead of nothing:

const action = e?.currentTarget?.action.replace(
  `${window.location.origin}${basename === "/" ? "" : basename}`,
  "/",
);

I am not sure if this has any implications with the way this library works, so i haven't submitted a PR yet. For now this seems to solve my issue but i'd love to see this being officially fixed in the library.

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