Closed Lehoczky closed 9 months ago
Hey,
I think that this issue can be caused by the fact that the url property of hit has already the frontend-tools
.
Because of that the code here creates a redirect to the current location with added hit.url that in your case is probably frontend-tools/something
.
Could you change the url so that it does not include the prefix frontend-tools
? Then it should be working as expected (for example, nuxt.com uses this Docsearch that way).
Hi Jakub,
Isn't the hit.url
property right here? It is used as href on the dom and if you click the url in dev tools, it navigates you to the right page:
and it is also equivalent with what nuxt content generates for that h3
element:
NuxtLink
components also use the base URL:
If I remove the whole base path like this:
transformItems(items) {
return items.map((item) => ({
...item,
url: item.url.replace( 'https://lehoczky.github.io/frontend-tools', ''),
}))
},
Then clicking on a search result is working, but the href
is essentially wrong, it should have frontend-tools
in it. If I click on this link now in the devtools, it goes to the 404 page:
Isn't it maybe caused by the baseUrl
property set in nuxt.config.ts? https://github.com/Lehoczky/frontend-tools/blob/5ca8ec84e2b23e5e004bb2bcc748d630a1b0a57a/nuxt.config.ts#L4
Maybe it is adding this /frontend-tools
automatically to your url while the link in the DocSearch seems to work correctly.
Yes, it's definitely caused by the baseUrl
, and I think I found the responsible line of code: nuxt/src/pages/runtime/plugins/router.ts#L53
Because the useRouter
composable is already using the baseUrl
, if we router.push()
anything, like we do here, in the component, that path will get appended to the base url. In my case we push frontend-tools/anything
while the router is already using frontend-tools
as a base and that's why we get frontent-tools/frontend-tools/anything
as a result.
Version
"@nuxtjs/algolia": "^1.9.0", "nuxt": "~3.6.5",
Reproduction Link
Since DocSearch is only granted for running documentation sites, I'm unfortunately unable to provide a minimal reproduction, but my site is open source. Let me know if you need any help.
Repo: https://github.com/Lehoczky/frontend-tools Running site: https://lehoczky.github.io/frontend-tools/
Steps to reproduce
What is Expected?
The user is being redirected to https://lehoczky.github.io/frontend-tools/frontend-tools/style-guide/#avoid-mental-mapping which shows the 404 page, because
frontend-tools
is in the URL twiceWhat is actually happening?
Navigate to https://lehoczky.github.io/frontend-tools/style-guide/#avoid-mental-mapping instead.