Minimal Router for petite-vue #83
-
Hi |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 11 replies
-
If you really need client-side routing, you should use regular Vue. petite-vue is made specifically to add a little bit of additional functionality on top of your server rendered page and it's not at all compatible with vue-router. If you don't need to share global state between different routes, you can of course just include petite-vue on multiple different server rendered pages. If you need your app to be a real SPA however then petite-vue is just not a right choice for that. |
Beta Was this translation helpful? Give feedback.
-
maybe Page? |
Beta Was this translation helpful? Give feedback.
-
I feel like we are trying to transform petite-vue into vue or at least to
be a replacement but the truth is that petite-vue wasn't created for this
kind of complexity.
…On Mon, 15 Aug 2022 at 11:29, niu tech ***@***.***> wrote:
@pwFoo <https://github.com/pwFoo> How about this:
Router({
'/one': () => createApp({OneApp}).mount(),
'/two': () => createApp({TwoApp}).mount(),
}).init()
—
Reply to this email directly, view it on GitHub
<#83 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACAO23NJP26OAAGEYHFNURDVZILXHANCNFSM5EDNQHYA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
*Ferran*
|
Beta Was this translation helpful? Give feedback.
-
@fparedlo Maybe I should take a look into vue3 too... |
Beta Was this translation helpful? Give feedback.
-
Working example (with main.jsimport { createApp } from "https://esm.run/petite-vue";
import page from "https://unpkg.com/page/page.mjs";
function Home() {
return {};
}
function Counter() {
return {
count: 0,
$template: `
<h1>Counter</h1>
My count is {{ count }}
<button @click="count++">++</button>
`,
};
}
function Gauge() {
return {
gauge: 0,
$template: `
<h1>Gauge</h1>
My gauge is {{ gauge }}
<button @click="gauge--">--</button>
<button @click="gauge++">++</button>
`,
};
}
const createPageHandler = (createScope) => () => {
const app = document.getElementById("app");
app.innerHTML = '<div v-scope="scope"></div>';
createApp({
get scope() {
return createScope();
},
}).mount();
};
page({ window });
page("/", createPageHandler(Home));
page("/counter", createPageHandler(Counter));
page("/gauge", createPageHandler(Gauge));
page(); index.html <body>
<nav>
<a href="/">Home</a>
<a href="/counter">Counter</a>
<a href="/gauge">Gauge</a>
</nav>
<div id="app"></div>
<script type="module" src="main.js"></script>
</body> |
Beta Was this translation helpful? Give feedback.
-
I created a npm library called petite-router to pair with petite-vue for my use-case. |
Beta Was this translation helpful? Give feedback.
If you really need client-side routing, you should use regular Vue. petite-vue is made specifically to add a little bit of additional functionality on top of your server rendered page and it's not at all compatible with vue-router. If you don't need to share global state between different routes, you can of course just include petite-vue on multiple different server rendered pages. If you need your app to be a real SPA however then petite-vue is just not a right choice for that.