Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 76 additions & 3 deletions workspaces/example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,82 @@
<legend>
<a href="/">Entrances</a>
</legend>
<div>
Default Matching Rules: <code>/\/(apple|banana|strawberries|home)(?:\.html?)?(\?|#|$).*/</code>
</div>
<ul>
<li>
<a href="/home">/home</a>
</li>
<li>
<a href="/home?">/home?</a>
</li>
<li>
<a href="/home?foo=foo">/home?foo=foo</a>
</li>
<li>
<a href="/home?foo=foo#hash">/home?foo=foo#hash</a>
</li>
</ul>
<ul>
<li>
<a href="/home#">/home#</a>
</li>
<li>
<a href="/home#hash">/home#hash</a>
</li>
<li>
<a href="/home#hash?foo=foo">/home#hash?foo=foo</a>
</li>
</ul>
<ul>
<li>
<a href="/home.html">/home.html</a>
</li>
<li>
<a href="/apple">/apple</a>
<a href="/home.html?">/home.html?</a>
</li>
<li>
<a href="/home.html?foo=foo">/home.html?foo=foo</a>
</li>
<li>
<a href="/home.html?foo=foo#hash">/home.html?foo=foo#hash</a>
</li>
</ul>
<ul>
<li>
<a href="/home.html#">/home.html#</a>
</li>
<li>
<a href="/home.html#hash">/home.html#hash</a>
</li>
<li>
<a href="/apple.html">/apple.html</a>
<a href="/home.html#hash?foo=foo">/home.html#hash?foo=foo</a>
</li>
</ul>
<ul>
<li>
<a href="/home.htm">/home.htm</a>
</li>
<li>
<a href="/home.htm?">/home.htm?</a>
</li>
<li>
<a href="/home.htm?foo=foo">/home.htm?foo=foo</a>
</li>
<li>
<a href="/home.htm?foo=foo#hash">/home.htm?foo=foo#hash</a>
</li>
</ul>
<ul>
<li>
<a href="/home.htm#">/home.htm#</a>
</li>
<li>
<a href="/home.htm#hash">/home.htm#hash</a>
</li>
<li>
<a href="/home.htm#hash?foo=foo">/home.htm#hash?foo=foo</a>
</li>
</ul>
</fieldset>
Expand All @@ -34,6 +98,9 @@
<li>
<a href="/">/ -> /index.html</a>
</li>
<li>
<a href="/home/">/home/ -> 404</a>
</li>
<li>
<a href="/infos">/infos -> /index.html</a>
</li>
Expand All @@ -43,6 +110,12 @@
<li>
<a href="/infos/index.html">/infos/index.html -> Infos Index</a>
</li>
<li>
<a href="/infos/home">/infos/home -> /home ⚠️</a>
</li>
<li>
<a href="/infos/home/">/infos/home/ -> Infos Home</a>
</li>
<li>
<a href="/infos/other">/infos/other -> /index.html</a>
</li>
Expand All @@ -69,4 +142,4 @@

</body>

</html>
</html>
15 changes: 15 additions & 0 deletions workspaces/example/infos/home/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Infos Home</title>
</head>

<body>
<h1>Infos Home</h1>
<a href="/">Back to root</a>
</body>

</html>
16 changes: 8 additions & 8 deletions workspaces/example/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ export default defineConfig({
* If you config your pages as above, this rewrite rules will be automatically generated.
* Otherwise you should manually write it, which will overwrite the default.
*/
rewrites: [
{
from: new RegExp(
normalizePath(`/${base}/(apple|banana|strawberries|home)`),
),
to: (ctx) => normalizePath(`/${base}/fruits/${ctx.match[1]}.html`),
},
],
// rewrites: [
// {
// from: new RegExp(
// normalizePath(`/${base}/(apple|banana|strawberries|home)`),
// ),
// to: (ctx) => normalizePath(`/${base}/fruits/${ctx.match[1]}.html`),
// },
// ],
/**
* Customize the history fallback rewrite rules for `preview server`.
* This option is almost the same with `rewrites`.
Expand Down
2 changes: 1 addition & 1 deletion workspaces/plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function createMpaPlugin<
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
rewrites: rewrites.concat([
{
from: new RegExp(normalizePath(`/${base}/(${Object.keys(inputMap).join('|')})`)),
from: new RegExp(`${normalizePath(`/${base}/`)}(${Object.keys(inputMap).join('|')})(?:\\.html?)?(\\?|#|$).*`),
to: ctx => {
return normalizePath(`/${base}/${inputMap[ctx.match[1]]}`);
},
Expand Down