nextra icon indicating copy to clipboard operation
nextra copied to clipboard

How to configure basePath in Nextra

Open t0t07 opened this issue 3 years ago • 3 comments

Hi,

I am using nextra-theme-docs. After I deploy the app on GitLab CI, my GitLab pages are live,

image

however, as you can see, assets loading fails.

image

This is because my site is live on http://aiinfra.book.pri.ibanyu.com/docs/, however it tries to load assets from http://aiinfra.book.pri.ibanyu.com/_next/static/chunks/main-b8578ac1074c64daef74.js. This is not working, while http://aiinfra.book.pri.ibanyu.com/docs/_next/static/chunks/main-b8578ac1074c64daef74.js exist. (Note the latter has a /docs inside)

I wonder how to configure my nextra app so that my app loads asset from http://aiinfra.book.pri.ibanyu.com/docs/_next/ rather than http://aiinfra.book.pri.ibanyu.com/_next/.

I have tried to edit my theme.config.js to update path: "/" to path: "/docs", and also add basePath: "/docs" (according to nextjs docs), however neither helps.

Any help? Thanks!

t0t07 avatar Apr 20 '21 12:04 t0t07

Ah i figure out why, I should add basePath: "/docs" to next.config.js rather than theme.config.js.

@shuding Is this a good practice?

t0t07 avatar Apr 20 '21 12:04 t0t07

Same issue not working for me, this is the config, throws 404

const withNextra = require('nextra')('nextra-theme-blog', './theme.config.js')
module.exports = withNextra()
module.exports = {
  basePath: '/docs',
}

varunharidas avatar Jan 28 '22 06:01 varunharidas

@varunharidas You should only have one module.exports below:

const withNextra = require('nextra')('nextra-theme-blog', './theme.config.js')
module.exports = withNextra()
module.exports = {
  basePath: '/docs',
}

Instead, it should be:

const withNextra = require('nextra')({
    theme: 'nextra-theme-blog',
    themeConfig: './theme.config.js',
    // optional: add `unstable_staticImage: true` to enable Nextra's auto image import
})
module.exports = withNextra({
    basePath: '/docs',
})

You can check out the rtdl-docs repo and the associated GitHub Pages site for a working example.

thtmnisamnstr avatar Feb 06 '22 14:02 thtmnisamnstr

closing since basePath works, if anyone has a similar problem, I'll reopen the issue

dimaMachina avatar Aug 20 '22 14:08 dimaMachina

@B2o5T what about broken paths in search results when I add basePath: '/docs',? The search results now have doubled the docs part of the path: localhost:3000/docs/docs/app-chain/components/app-chain-testnet-faucet

raproid avatar Aug 30 '22 17:08 raproid

@raproid do you use latest beta?

dimaMachina avatar Aug 30 '22 17:08 dimaMachina

@B2o5T no, I'm using "next": "^12.2.0", "nextra": "^2.0.0-beta.6", "nextra-theme-docs": "^2.0.0-beta.6",

raproid avatar Aug 30 '22 18:08 raproid

So, it's the beta 6.

raproid avatar Aug 30 '22 18:08 raproid

Try to use beta 21

dimaMachina avatar Aug 30 '22 18:08 dimaMachina

image

getting this when using beta 21

raproid avatar Aug 30 '22 20:08 raproid

How to import and declare callouts correctly in beta 21?

raproid avatar Aug 30 '22 20:08 raproid

import { Callout } from ‘nextra-theme-docs’

dimaMachina avatar Aug 30 '22 21:08 dimaMachina

worked it out, thx

How to fix the position of the theme switcher? It's on the left and facing left beyond the screen. image

raproid avatar Aug 30 '22 22:08 raproid

and if there's not .md/.mdx file within a section but another section instead I'm getting 404. e.g. if I click on Affiliated Chains I'm getting 404 as there's only a folder within this folder, no .md/.mdx file to generate a page from. image

raproid avatar Aug 30 '22 22:08 raproid

Is the search index built locally? Testing it on localhost, I'm typing a word that sure is in many files in many subfolders under pages yet I see no search results for it at all. What search engine does Nextra use by default? And how is the index built?

raproid avatar Aug 30 '22 22:08 raproid

How to fix the position of the theme switcher?

Will be fixed in next release https://github.com/shuding/nextra/pull/763

dimaMachina avatar Aug 31 '22 01:08 dimaMachina

Is the search index built locally?

Try to next build and next start, in dev env there are some limitations

dimaMachina avatar Aug 31 '22 01:08 dimaMachina

@B2o5T what about this bug? https://github.com/shuding/nextra/issues/137#issuecomment-1232224587

raproid avatar Aug 31 '22 09:08 raproid

Can you show a reproduction repo with this issue?

dimaMachina avatar Aug 31 '22 09:08 dimaMachina

Of course. https://github.com/raproid/raproid.github.io/tree/stage

yarn then yarn next

raproid avatar Aug 31 '22 15:08 raproid

And then try to go App Chains > Affiliated Chains

raproid avatar Aug 31 '22 15:08 raproid

Also, what tab tag is to use in beta 21?

<Nextra.Tabs><Nextra.Tab></Nextra.Tab></Nextra.Tabs> gives me the "Error: Expected object Nextra to be defined: you likely forgot to import, pass, or provide it." error.

That tab tag worked in beta 6.

raproid avatar Aug 31 '22 19:08 raproid

Hi @raproid, will take a look at near days

dimaMachina avatar Sep 01 '22 13:09 dimaMachina

@B2o5T Hi!

Any news about

  1. What to replace with the <Nextra.Tabs> tag in latest betas?
  2. The bug? You can see it live on https://raproid-github-io.vercel.app/ under App Chains > Affiliated Chains and the direct link is https://raproid-github-io.vercel.app/app-chain/affiliated-chain/bnb-sidechain/

Basically, Nextra treats sidebar menu items as active links, regardless if an item is an actual page or a folder. Ofc the user sees 404 when clicking on an item that is a folder.

raproid avatar Sep 05 '22 13:09 raproid

for the 1st - you should use import { Tabs, Tab } from 'nextra-theme-docs' for 2nd I didn't take a look yet

dimaMachina avatar Sep 05 '22 20:09 dimaMachina

@B2o5T would be really nice if you could. That's a major bug for Nextra. Beta 24 is very good. Thank you for your work!

raproid avatar Sep 06 '22 16:09 raproid

@raproid I can confirm the existing issue on the current beta, but on the not released version of nextra it works fine, so wait little bit, it will be fixed on next beta

PR that fixes your issue https://github.com/shuding/nextra/pull/811

dimaMachina avatar Sep 06 '22 19:09 dimaMachina

The basePath should not be tied to NextJS's own config, imho.

Theme should have its own basePath.

I currently use Nextra within an existing project SaaS platform, so if I change the basePath, it breaks the entire app's routing.

NasirAbdullahSyed avatar Oct 27 '23 06:10 NasirAbdullahSyed

The basePath should not be tied to NextJS's own config, imho.

Theme should have its own basePath.

I currently use Nextra within an existing project SaaS platform, so if I change the basePath, it breaks the entire app's routing.

Yes I agree, it seems they want nextra to be its own standalone app, but I want to integrate into an existing app where the "/" is already taken.

iqbal125 avatar Nov 11 '23 21:11 iqbal125

Any updates here? I wanna do it too

NotDemonix avatar Feb 01 '24 21:02 NotDemonix