api-platform / create-client

Generate React or Vue.js-based Progressive Web Apps from an Hydra-enabled API. Also support React Native.
https://api-platform.com/docs/client-generator/
MIT License
374 stars 132 forks source link

React generator has inconsistent paths generation #376

Open 29Hido opened 9 months ago

29Hido commented 9 months ago

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