create-client icon indicating copy to clipboard operation
create-client copied to clipboard

React generator has inconsistent paths generation

Open 29Hido opened this issue 1 year ago • 0 comments

Description
React generator has problem with paths for resources. I generated a client using https://demo.api-platform.com/, while the generated routes have paths like /admin/books/create the Show components has paths like <Navigate to="/books/" replace />

How to reproduce

  1. Generate a client with rm -rf ./tmp && yarn build && ENTRYPOINT=https://demo.api-platform.com/ ./testgen.sh react
  2. Go to tmp/react/routes/book.tsx you will see
const routes = [
  <Route path="/admin/books/create" element={<Create />} key="create" />,
  <Route path="/admin/books/edit/:id" element={<Update />} key="update" />,
  <Route path="/admin/books/show/:id" element={<Show />} key="show" />,
  <Route path="/admin/books" element={<List />} key="list" />,
  <Route path="/admin/books/:page" element={<List />} key="page" />,
];
  1. Go to tmp/react/components/book/Show.tsx and you can see
<Link to="/books/" className="btn btn-primary">
        Back to list
</Link>

image

Possible Solution
Use the same variable in all template when generating routes and links

Additional Context
PR here : https://github.com/api-platform/create-client/pull/377

29Hido avatar Feb 28 '24 13:02 29Hido