<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Brad Pillow</title>
    <description>The latest articles on DEV Community by Brad Pillow (@pillowsoft).</description>
    <link>https://dev.to/pillowsoft</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F171441%2F8233af98-addd-4243-95db-5889fcaad6c9.jpeg</url>
      <title>DEV Community: Brad Pillow</title>
      <link>https://dev.to/pillowsoft</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pillowsoft"/>
    <language>en</language>
    <item>
      <title>Svelte, Ionic and the Ionic Router</title>
      <dc:creator>Brad Pillow</dc:creator>
      <pubDate>Mon, 13 Sep 2021 19:51:44 +0000</pubDate>
      <link>https://dev.to/pillowsoft/svelte-ionic-and-the-ionic-router-kco</link>
      <guid>https://dev.to/pillowsoft/svelte-ionic-and-the-ionic-router-kco</guid>
      <description>&lt;p&gt;Since Svelte does not use a virtual-dom, it turns out the interoperability with web components is very good. Svelte is capable of creating web components as well. These two features make it play well with with Ionic and the Ionic router.&lt;/p&gt;

&lt;p&gt;You can see an example on the svelte REPL &lt;a href="https://svelte.dev/repl/ebd0e48a2acf487799aec9575ccd1ef0?version=3.42.5"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://ionicframework.com/docs/api/nav"&gt;Ionic router&lt;/a&gt; has a good emulation of the routing transitions used on iOS and Android and I think the combination of svelte and Ionic are quite powerful.&lt;/p&gt;

&lt;p&gt;In the example, we load the Ionic web components and CSS thought a CDN:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;svelte:head&amp;gt;
  &amp;lt;script
    type="module"
    src="https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/ionic.esm.js"&amp;gt;
  &amp;lt;/script&amp;gt;
  &amp;lt;script
    nomodule
    src="https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/ionic.js"&amp;gt;
  &amp;lt;/script&amp;gt;
  &amp;lt;link
    rel="stylesheet"
    href="https://cdn.jsdelivr.net/npm/@ionic/core/css/ionic.bundle.css" /&amp;gt;
&amp;lt;/svelte:head&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NOTE: It may look like you are loading a lot of code, but Ionic's web components are instantiated lazily, so only loaded when used. This improves your startup performance and Lighthouse scores.&lt;/p&gt;

&lt;p&gt;The Ionic router works by routing to to web components. I.e. the way we make this work with svelte, is that we create a web component out of any route/page and refer to it in the  tag.&lt;/p&gt;

&lt;p&gt;This code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { register } from "svelte-custom-elements";
import NavHome from "./NavHome.svelte";

const isRegistered = function(name) {
    return document.createElement(name).constructor !== HTMLElement;
};

if (!isRegistered("nav-home")) {
    register("nav-home", NavHome, []);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;essentially imports our svelte component and then registers it as a web component called "nav-home".  NOTE: web component names must be unique. The last lines above are to ensure that when using hot module reload, the web component is not redefined, else you will get an error.&lt;/p&gt;

&lt;p&gt;The Ionic router has path based and programmatic routing, which I will explore more in future posts.&lt;/p&gt;

</description>
      <category>svelte</category>
      <category>ionic</category>
      <category>webcomponents</category>
    </item>
  </channel>
</rss>
