I think one of the major drawbacks using Blaze after using React is relying on helpers whereas in React (or Svelte) you get the full power of JS inside your templates.
For ease though it’s hard to beat Blaze + ViewModel. ViewModel’s mixins alone make my templates so much easier to write
Svelte is very much router-agnostic. In one of our apps we use ostrio:flow-router-extra, since we also use Blaze in the same app. In another app we’re using our custom “router”, as there’s only ~5 routes. Our third Svelte app is a Sapper export, a static site, and that’s using the filesystem based router included in Sapper. There’s also a bunch of “designed for Svelte” routers, but you can also just use page.js, or if you want a really tiny router, try Navaid.
Just starting out now, and running into a 'target' is a required option. Frustrating! I’ve read that the npm and meteor versions need to match (which I think they do), anyone run into this?
Sorry I meant to suggest that you’d have to extract any such JS logic to template helpers, whereas in React/Svelte you could do it inline <p>1 + 1 = {1 + 1}</p>
Struggling to get any of the routers (svelte-routing or svero) working with my setup. Svero seems to bring back the target error and svelte-routing seems to cause all sort of errors, possibly due to it needing server-side configuration too.
Has anyone had any experience getting either of these (or similar) routers working with Svelte? Thanks!
Navaid was simple to setup and is very minimal in terms of the API, so if it covers your requirements I’d give that a try. Can’t say why the others wouldn’t work - sounds strange and I’d first look into making sure the version of Svelte used by svelte:compiler matches the version of Svelte in your app - take a peek inside node_modules/svelte/package.json and verify you have the correct version installed?
As an alternative, I’ve been using a component for this purpose.
// Tracker.svelte
<script>
import { Tracker } from 'meteor/tracker';
import { Meteor } from 'meteor/meteor';
import { onDestroy } from 'svelte';
export let deps = [];
export let fn;
const dep = new Tracker.Dependency;
$: {
deps;
dep.changed();
}
const computation = Tracker.autorun(() => {
dep.depend();
fn();
});
onDestroy(() => {
computation.stop();
})
</script>
<slot></slot>
Then you’d use it as a wrapper,
<script>
export let id;
let model;
function computation() {
model = Model.findOne({ _id: id });
}
</script>
<Tracker deps={[id]} fn={computation}>
<h1>{model.name}</h1>
</Tracker>
Though I’ll admit, I only did it this way because I thought onDestroy had to be inside a component.
Thanks, I must confess to be unsure how to best ensure that the versions match. I’m pretty sure I specified the version when installing but now find they are slightly out. Can I just update the version number inside .meteor/packages or is it best to do it in the .package.json? Are there any other commands to run to ensure they update? Thanks!
Incidentally I also got a version of navaid working nicely using the author’s svelte-demo https://github.com/lukeed/svelte-demo although I’m not sure if it’s possible using navaid to navigate programatically?
You want the npm package to match the meteor package. So get the meteor package up to date, and then lock the npm version with meteor npm install svelte@<version.
Regarding routing, I use svelte-routing in my app with no issues. No special setup.
Make sure you meteor remove blaze-html-templates and meteor add static-html. You want to serve the static main.html so you can document.querySelector it. That should fix you target required error.
Thanks! Can I just check if the version ends with _1 should that also be specified in the npm version or is that bit dropped? Eg current latest package is 3.6.7_1. TIA
Your other tip about adding/remove the HTML packages seems to have sorted it! Thanks, I didn’t notice that in the package readme but perhaps I should have thought of it! Thanks
So frustrating it works fine then I try and install either svelte-routing or svero. With svero the target error comes back and with svelte-routing I get a whole host of other errors (I believe might be due to this package not being compiled?)
Thanks! Here is a repo, I’ve added svero and svelte-routing but currently this is an attempt with svero but I think their setups are extremely similar.