core
core copied to clipboard
dotcms lib: Get Nav Is Broken
Describe the bug
The latest version (v0.0.18
) of our dotCMS JavaScript Library
has been broken for over a year. See the npm package here.
If we try to use the dotCMS.nav.get()
method, it is always returning an empty array.
const nav = await dotCMS.nav.get(String(deep), location);
// Always returns an empty array.
console.log(nav.children);
To Reproduce
We can test it in one of our custom nextJS
projects or in a new one.
Let's start by reproducing the error in our Dotcms NextJS Starter project:
- Clone the project.
- Run
yarn dotcms@latest
(The current version in this project isv0.0.17
which is working normally) - Run
yarn
(Install all dependencies). - Start the project (Read how to do it in the README.md)
- See the error. Now the navigation only has one options
home
.
v0.0.18 | v0.0.17 |
---|---|
We can also reproducing in a new JavaScript Project:
- Create a JavaScript Project using
npm
. Could be: NextJS, ReactJS, or Angular. - Run
yarn dotcms@latest
- Instance a
dotCMS APP
:
// Dependencies
import { initDotCMS } from 'dotcms'
export const dotCMS = initDotCMS({
host: ${your_host}
token: ${your_token}
})
- Try to use the
await dotCMS.nav.get(String(deep), location);
method. - See the Error.
Expected behavior
The method should bring the navigation items as we would expect.
Additional context
It looks like it is due to a change on the params made in this PR.
As you can see in the PR, in the DotApiNavigation.ts
file, the depth
param was changed to deep
.
If we follow the documentation [dotcms navigation rest api], the correct param is:
.request({
url: `/api/v1/nav/${location}`,
params: {
depth: deep
}
})
Acceptance criteria
- Should bring the navigation items as expected.
- Try the methods and confirm that they are working normally.
- Update the dotCMS package.
P.S: You can reach me if you have any questions about how to start our Dotcms NextJS Starter project.