2026-02-06 03:34:50 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="hash-vs-history-demo">
|
|
|
|
|
|
<div class="demo-header">
|
2026-02-13 22:10:03 +08:00
|
|
|
|
<span class="icon">⚖️</span>
|
|
|
|
|
|
<span class="title">路由模式对比</span>
|
|
|
|
|
|
<span class="subtitle">Hash vs History</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="intro-text">
|
|
|
|
|
|
想象你在<span class="highlight">邮寄包裹</span>:Hash模式像是把地址写在<span class="highlight">便签条</span>上(#后面),History模式则是直接写在<span class="highlight">信封</span>上。前者简单但不够正式,后者美观但需要服务端配合。
|
2026-02-06 03:34:50 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="comparison-container">
|
|
|
|
|
|
<!-- Hash Mode -->
|
|
|
|
|
|
<div class="mode-column">
|
|
|
|
|
|
<div class="mode-header hash">
|
|
|
|
|
|
<span class="mode-icon">#</span>
|
|
|
|
|
|
<span class="mode-title">Hash 模式</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="browser-mockup">
|
|
|
|
|
|
<div class="browser-toolbar">
|
|
|
|
|
|
<div class="window-controls">
|
2026-02-18 17:38:10 +08:00
|
|
|
|
<span class="dot red" />
|
|
|
|
|
|
<span class="dot yellow" />
|
|
|
|
|
|
<span class="dot green" />
|
2026-02-06 03:34:50 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="address-bar">
|
|
|
|
|
|
<span class="protocol">https://</span>
|
|
|
|
|
|
<span class="host">example.com</span>
|
|
|
|
|
|
<span class="hash-path">/#/{{ hashPath }}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="browser-viewport">
|
|
|
|
|
|
<nav class="nav-bar">
|
|
|
|
|
|
<a
|
|
|
|
|
|
v-for="item in navItems"
|
|
|
|
|
|
:key="item.path"
|
|
|
|
|
|
:class="['nav-item', { active: hashPath === item.path }]"
|
|
|
|
|
|
@click="hashPath = item.path"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ item.name }}
|
|
|
|
|
|
</a>
|
|
|
|
|
|
</nav>
|
|
|
|
|
|
<div class="page-content">
|
|
|
|
|
|
<h3>{{ getPageTitle(hashPath) }}</h3>
|
|
|
|
|
|
<p>{{ getPageContent(hashPath) }}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="characteristics">
|
|
|
|
|
|
<div class="char-item">
|
2026-02-13 22:10:03 +08:00
|
|
|
|
<span class="char-label">兼容性</span>
|
2026-02-06 03:34:50 +08:00
|
|
|
|
<span class="badge good">IE8+</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="char-item">
|
|
|
|
|
|
<span class="char-label">服务端配置</span>
|
|
|
|
|
|
<span class="badge good">无需配置</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="char-item">
|
|
|
|
|
|
<span class="char-label">SEO友好度</span>
|
|
|
|
|
|
<span class="badge bad">较差</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- History Mode -->
|
|
|
|
|
|
<div class="mode-column">
|
|
|
|
|
|
<div class="mode-header history">
|
|
|
|
|
|
<span class="mode-icon">/</span>
|
|
|
|
|
|
<span class="mode-title">History 模式</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="browser-mockup">
|
|
|
|
|
|
<div class="browser-toolbar">
|
|
|
|
|
|
<div class="window-controls">
|
2026-02-18 17:38:10 +08:00
|
|
|
|
<span class="dot red" />
|
|
|
|
|
|
<span class="dot yellow" />
|
|
|
|
|
|
<span class="dot green" />
|
2026-02-06 03:34:50 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="address-bar">
|
|
|
|
|
|
<span class="protocol">https://</span>
|
|
|
|
|
|
<span class="host">example.com</span>
|
|
|
|
|
|
<span class="history-path">/{{ historyPath }}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="browser-viewport">
|
|
|
|
|
|
<nav class="nav-bar">
|
|
|
|
|
|
<a
|
|
|
|
|
|
v-for="item in navItems"
|
|
|
|
|
|
:key="item.path"
|
|
|
|
|
|
:class="['nav-item', { active: historyPath === item.path }]"
|
|
|
|
|
|
@click="historyPath = item.path"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ item.name }}
|
|
|
|
|
|
</a>
|
|
|
|
|
|
</nav>
|
|
|
|
|
|
<div class="page-content">
|
|
|
|
|
|
<h3>{{ getPageTitle(historyPath) }}</h3>
|
|
|
|
|
|
<p>{{ getPageContent(historyPath) }}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="characteristics">
|
|
|
|
|
|
<div class="char-item">
|
2026-02-13 22:10:03 +08:00
|
|
|
|
<span class="char-label">兼容性</span>
|
2026-02-06 03:34:50 +08:00
|
|
|
|
<span class="badge medium">IE10+</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="char-item">
|
|
|
|
|
|
<span class="char-label">服务端配置</span>
|
|
|
|
|
|
<span class="badge warn">需要配置</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="char-item">
|
|
|
|
|
|
<span class="char-label">SEO友好度</span>
|
|
|
|
|
|
<span class="badge good">良好</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-02-13 22:10:03 +08:00
|
|
|
|
<div class="info-box">
|
|
|
|
|
|
<span class="icon">💡</span>
|
|
|
|
|
|
<strong>选择建议:</strong>现代项目优先选History模式(URL美观、SEO友好),如果需要兼容老浏览器或无法修改服务端配置,再用Hash模式。
|
2026-02-06 03:34:50 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
|
import { ref } from 'vue'
|
|
|
|
|
|
|
|
|
|
|
|
const hashPath = ref('home')
|
|
|
|
|
|
const historyPath = ref('home')
|
|
|
|
|
|
|
|
|
|
|
|
const navItems = [
|
|
|
|
|
|
{ name: '首页', path: 'home' },
|
|
|
|
|
|
{ name: '产品', path: 'products' },
|
|
|
|
|
|
{ name: '关于', path: 'about' }
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
const getPageTitle = (path) => {
|
|
|
|
|
|
const titles = {
|
|
|
|
|
|
home: '首页',
|
|
|
|
|
|
products: '产品中心',
|
|
|
|
|
|
about: '关于我们'
|
|
|
|
|
|
}
|
|
|
|
|
|
return titles[path] || '首页'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const getPageContent = (path) => {
|
|
|
|
|
|
const contents = {
|
|
|
|
|
|
home: '欢迎来到我们的网站!这是SPA的首页,所有页面切换都在前端完成,无需刷新。',
|
|
|
|
|
|
products: '这里展示了我们的核心产品系列。SPA让浏览体验更流畅,切换更快。',
|
|
|
|
|
|
about: '了解更多关于我们的故事。SPA模式下,页面间跳转几乎没有延迟。'
|
|
|
|
|
|
}
|
|
|
|
|
|
return contents[path] || contents.home
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.hash-vs-history-demo {
|
2026-02-13 22:10:03 +08:00
|
|
|
|
border: 1px solid var(--vp-c-divider);
|
2026-02-14 20:23:34 +08:00
|
|
|
|
border-radius: 6px;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
background: var(--vp-c-bg-soft);
|
2026-02-14 20:23:34 +08:00
|
|
|
|
padding: 0.75rem;
|
|
|
|
|
|
margin: 0.5rem 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-02-06 03:34:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.demo-header {
|
2026-02-13 22:10:03 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 0.5rem;
|
|
|
|
|
|
margin-bottom: 0.75rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-13 22:10:03 +08:00
|
|
|
|
.demo-header .icon { font-size: 1.25rem; }
|
|
|
|
|
|
.demo-header .title { font-weight: bold; font-size: 1rem; }
|
|
|
|
|
|
.demo-header .subtitle { color: var(--vp-c-text-2); font-size: 0.85rem; margin-left: 0.5rem; }
|
2026-02-06 03:34:50 +08:00
|
|
|
|
|
2026-02-13 22:10:03 +08:00
|
|
|
|
.intro-text {
|
|
|
|
|
|
font-size: 0.9rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
color: var(--vp-c-text-2);
|
2026-02-13 22:10:03 +08:00
|
|
|
|
line-height: 1.6;
|
|
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
|
|
padding: 0.75rem;
|
|
|
|
|
|
background: var(--vp-c-bg);
|
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.intro-text .highlight {
|
|
|
|
|
|
color: var(--vp-c-brand-1);
|
|
|
|
|
|
font-weight: 500;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.comparison-container {
|
|
|
|
|
|
display: grid;
|
|
|
|
|
|
grid-template-columns: 1fr 1fr;
|
2026-02-13 22:10:03 +08:00
|
|
|
|
gap: 1rem;
|
|
|
|
|
|
margin-bottom: 1rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.mode-column {
|
|
|
|
|
|
background: var(--vp-c-bg);
|
2026-02-14 20:23:34 +08:00
|
|
|
|
border-radius: 6px;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.mode-header {
|
2026-02-13 22:10:03 +08:00
|
|
|
|
padding: 0.75rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
2026-02-13 22:10:03 +08:00
|
|
|
|
gap: 0.5rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.mode-header.hash {
|
|
|
|
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
|
|
|
|
color: white;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.mode-header.history {
|
|
|
|
|
|
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
|
|
|
|
|
color: white;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.mode-icon {
|
2026-02-13 22:10:03 +08:00
|
|
|
|
font-size: 1rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
font-weight: bold;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.mode-title {
|
2026-02-13 22:10:03 +08:00
|
|
|
|
font-size: 0.9rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.browser-mockup {
|
|
|
|
|
|
border-bottom: 1px solid var(--vp-c-divider);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.browser-toolbar {
|
|
|
|
|
|
background: var(--vp-c-bg-soft);
|
2026-02-13 22:10:03 +08:00
|
|
|
|
padding: 0.5rem 0.75rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
2026-02-13 22:10:03 +08:00
|
|
|
|
gap: 0.5rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.window-controls {
|
|
|
|
|
|
display: flex;
|
2026-02-13 22:10:03 +08:00
|
|
|
|
gap: 0.375rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.dot {
|
|
|
|
|
|
width: 10px;
|
|
|
|
|
|
height: 10px;
|
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.dot.red { background: #ff5f56; }
|
|
|
|
|
|
.dot.yellow { background: #ffbd2e; }
|
|
|
|
|
|
.dot.green { background: #27c93f; }
|
|
|
|
|
|
|
|
|
|
|
|
.address-bar {
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
background: var(--vp-c-bg);
|
2026-02-13 22:10:03 +08:00
|
|
|
|
padding: 0.25rem 0.5rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
border-radius: 4px;
|
2026-02-13 22:10:03 +08:00
|
|
|
|
font-size: 0.7rem;
|
|
|
|
|
|
font-family: monospace;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.protocol, .host { color: var(--vp-c-text-3); }
|
|
|
|
|
|
.hash-path { color: #e06c75; font-weight: 500; }
|
|
|
|
|
|
.history-path { color: #61afef; font-weight: 500; }
|
|
|
|
|
|
|
|
|
|
|
|
.browser-viewport {
|
|
|
|
|
|
display: flex;
|
2026-02-13 22:10:03 +08:00
|
|
|
|
min-height: 120px;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.nav-bar {
|
2026-02-13 22:10:03 +08:00
|
|
|
|
width: 60px;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
background: var(--vp-c-bg-soft);
|
2026-02-13 22:10:03 +08:00
|
|
|
|
padding: 0.5rem 0;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
border-right: 1px solid var(--vp-c-divider);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.nav-item {
|
|
|
|
|
|
display: block;
|
2026-02-13 22:10:03 +08:00
|
|
|
|
padding: 0.5rem 0.5rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
color: var(--vp-c-text-2);
|
2026-02-13 22:10:03 +08:00
|
|
|
|
font-size: 0.75rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
transition: all 0.2s;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.nav-item:hover {
|
|
|
|
|
|
background: var(--vp-c-bg);
|
|
|
|
|
|
color: var(--vp-c-text-1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.nav-item.active {
|
|
|
|
|
|
background: var(--vp-c-brand-soft);
|
|
|
|
|
|
color: var(--vp-c-brand);
|
|
|
|
|
|
border-right: 2px solid var(--vp-c-brand);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.page-content {
|
|
|
|
|
|
flex: 1;
|
2026-02-13 22:10:03 +08:00
|
|
|
|
padding: 0.75rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.page-content h3 {
|
2026-02-13 22:10:03 +08:00
|
|
|
|
margin: 0 0 0.5rem 0;
|
|
|
|
|
|
font-size: 0.9rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
color: var(--vp-c-text-1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.page-content p {
|
|
|
|
|
|
margin: 0;
|
2026-02-13 22:10:03 +08:00
|
|
|
|
font-size: 0.75rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
color: var(--vp-c-text-2);
|
2026-02-13 22:10:03 +08:00
|
|
|
|
line-height: 1.4;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.characteristics {
|
2026-02-13 22:10:03 +08:00
|
|
|
|
padding: 0.75rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.char-item {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
align-items: center;
|
2026-02-13 22:10:03 +08:00
|
|
|
|
padding: 0.5rem 0;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
border-bottom: 1px solid var(--vp-c-divider);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.char-item:last-child {
|
|
|
|
|
|
border-bottom: none;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.char-label {
|
2026-02-13 22:10:03 +08:00
|
|
|
|
font-size: 0.75rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
color: var(--vp-c-text-2);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.badge {
|
2026-02-13 22:10:03 +08:00
|
|
|
|
padding: 0.125rem 0.5rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
border-radius: 12px;
|
2026-02-13 22:10:03 +08:00
|
|
|
|
font-size: 0.65rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.badge.good {
|
|
|
|
|
|
background: rgba(39, 201, 63, 0.15);
|
|
|
|
|
|
color: #27c93f;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.badge.medium {
|
|
|
|
|
|
background: rgba(255, 189, 46, 0.15);
|
|
|
|
|
|
color: #ffbd2e;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.badge.warn {
|
|
|
|
|
|
background: rgba(255, 149, 0, 0.15);
|
|
|
|
|
|
color: #ff9500;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.badge.bad {
|
|
|
|
|
|
background: rgba(255, 95, 86, 0.15);
|
|
|
|
|
|
color: #ff5f56;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-13 22:10:03 +08:00
|
|
|
|
.info-box {
|
|
|
|
|
|
background: var(--vp-c-bg-alt);
|
|
|
|
|
|
padding: 0.75rem;
|
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
font-size: 0.85rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
color: var(--vp-c-text-2);
|
2026-02-13 22:10:03 +08:00
|
|
|
|
margin-top: 1rem;
|
2026-02-06 03:34:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-13 22:10:03 +08:00
|
|
|
|
.info-box .icon { margin-right: 0.25rem; }
|
2026-02-06 03:34:50 +08:00
|
|
|
|
|
2026-02-13 22:10:03 +08:00
|
|
|
|
@media (max-width: 768px) {
|
2026-02-06 03:34:50 +08:00
|
|
|
|
.comparison-container {
|
|
|
|
|
|
grid-template-columns: 1fr;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|