fix: 修复教程简介中链接点击跳转 URL 缺少 base URL 问题
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { defineConfig } from 'vitepress'
|
import { defineConfig } from 'vitepress'
|
||||||
|
import { base } from '../env.mts'
|
||||||
import { sidebar } from '../sidebar.mts'
|
import { sidebar } from '../sidebar.mts'
|
||||||
import { nav } from '../nav.mts'
|
import { nav } from '../nav.mts'
|
||||||
import {
|
import {
|
||||||
@@ -50,7 +51,7 @@ export default defineConfig({
|
|||||||
title: "就这么弄 (🚧 施工中)",
|
title: "就这么弄 (🚧 施工中)",
|
||||||
description: "简单步骤与实用技巧",
|
description: "简单步骤与实用技巧",
|
||||||
|
|
||||||
base: '/tutorials/',
|
base: base,
|
||||||
locales: {
|
locales: {
|
||||||
root: {
|
root: {
|
||||||
label: '简体中文',
|
label: '简体中文',
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useRouter, DefaultTheme } from 'vitepress';
|
import { useRouter, DefaultTheme } from 'vitepress';
|
||||||
|
import { base } from '../env.mts';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
base?: string,
|
base?: string,
|
||||||
@@ -38,7 +39,8 @@ const props = defineProps<{
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
function goTo(link: string) {
|
function goTo(link: string) {
|
||||||
const target = (props.base || '') + link?.replace('.md', '.html')
|
const baseUrl = (base.endsWith('/') ? base.substring(0, base.length - 1) : base)
|
||||||
|
const target = baseUrl + (props.base || '') + link?.replace('.md', '.html')
|
||||||
console.log('base', props.base)
|
console.log('base', props.base)
|
||||||
console.log('link', link)
|
console.log('link', link)
|
||||||
console.log('target', target)
|
console.log('target', target)
|
||||||
|
5
docs/env.mts
Normal file
5
docs/env.mts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
// 全局配置
|
||||||
|
|
||||||
|
// 部署后网站的 base URL。
|
||||||
|
// 注意:前后都带 /
|
||||||
|
export const base = '/tutorials/'
|
Reference in New Issue
Block a user