Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Support multi-page routing entries ending with / #4522

Open
akbq2008 opened this issue Feb 10, 2025 · 3 comments
Open

[Feature]: Support multi-page routing entries ending with / #4522

akbq2008 opened this issue Feb 10, 2025 · 3 comments

Comments

@akbq2008
Copy link

akbq2008 commented Feb 10, 2025

What problem does this feature solve?

为啥需要要按/结尾的原因

本地有http://localhost:3000/app/train/a 路由,在本地热更新或者刷新后会导致页面404

当前虽然这个配置可以解决 http://localhost:3000/app/train/
按如上形式运行,但是多了一些冗余代码,希望可以增加属性支持直接按/结尾运行。

let publicPath = ''
let outputDir = ''
let entry: any = {}
if (process.env.mode?.includes('hotel')) {
  publicPath = process.env.NODE_ENV !== 'development' ? '/trip/app/' : '/app/'
  outputDir = 'app'
  entry.index = './src/main.ts'
} else if (process.env.mode?.includes('train')) {
  publicPath = process.env.NODE_ENV !== 'development' ? '/trip/app/train/' : '/app/train/'
  outputDir = 'app/train'
  if (process.env.NODE_ENV === 'development') {
    entry.index = './src/train.ts'
  } else {
    entry.train = './src/train.ts'
  }
}


export default defineConfig({
  source: {
    entry,
  },
  html: {
    template: 'public/index.html'
  },
  output: {
    assetPrefix: publicPath,
    distPath: {
      root: outputDir
    }
  },
  dev: {
    assetPrefix: publicPath
  },
  server: {
    base: process.env.mode === 'train' ? '/app/train/' : '/app/',
  }
})

What does the proposed API look like?

html 配置中新增属性?

@chenjiahan chenjiahan changed the title [Feature]: 支持多页面路由entry按/结尾 [Feature]: Support multi-page routing entries ending with / Feb 10, 2025
@chenjiahan
Copy link
Member

Hi, you can try this:

export default {
  html: {
    outputStructure: 'nested',
  },
};

See: https://rsbuild.dev/config/html/output-structure

@akbq2008
Copy link
Author

Hi, you can try this:

export default {
html: {
outputStructure: 'nested',
},
};
See: https://rsbuild.dev/config/html/output-structure

let publicPath = ''
let outputDir = ''
let entry: any = {}
if (process.env.mode?.includes('hotel')) {
  publicPath = process.env.NODE_ENV !== 'development' ? '/trip/app/' : '/app/'
  outputDir = 'app'
  entry.index = './src/main.ts'
} else if (process.env.mode?.includes('train')) {
  publicPath = process.env.NODE_ENV !== 'development' ? '/trip/app/train/' : '/app/train/'
  outputDir = 'app/train'
  entry.train= './src/train.ts'
}


export default defineConfig({
  source: {
    entry,
  },
  html: {
    template: 'public/index.html',
    outputStructure: 'nested',
  },
  output: {
    assetPrefix: publicPath,
    distPath: {
      root: outputDir
    }
  },
  dev: {
    assetPrefix: publicPath
  },
  server: {
    base: '/app/,
  }
})

thank you for your reply. I tried it, but it cant't work fine.

Local: http://localhost:3000/fcapp/train

Copy link
Contributor

Hello @akbq2008. Please provide a reproduction repository or online demo. For background, see Why reproductions are required. Thanks ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants