Help us understand the problem. What is going on with this article?

svelte-spa-routerを使ってみる

svelteとsvelte-spa-routerでSPAを作る

Svelte
Svelte-spa-router
Svelteテンプレート

degetをインストール
$ npm install -g degit
degetでテンプレートをダウンロード
$ degit sveltejs/template svelte-app
起動してみる
$ cd svelte-app
$ npm install
$ npm run dev
svelte-spa-routerのインストール
$ npm install svelte-spa-router

app.svelteにRouterタグを設置

svelte-app/src/app.svelte
<script>
  import Router from 'svelte-spa-router' #svelte-spa-routerをインポートする
</script>

<body>
    <Router {routes}/> #パスに対してマッチしたコンポーネントを描画
</body>

app.svelteにコンポーネントとルーティング設定を追加

svelte-app/src/app.svelte
<script>
import Router from 'svelte-spa-router'
import Home from './routes/home.svelte'
import Showpage from './routes/showpage.svelte'

const routes = {
    '/': Home,
    '/showpage/': Showpage,
}
</script>

<body>
    <Router {routes}/>
</body>

home.svelteを作成しshowpageへのリンクを設置

svelte-app/src/routes/home.svelte
<script>
  import {link} from 'svelte-spa-router' #svelte-spa-routerのlinkをインポートする
</script>

<h1>Homepage</h1>
<a href="/showpage" use:link>showpageへ</a>

showpage.svelteを作成しhomeへのリンクを設置

svelte-app/src/routes/showpage.svelte
<script>
  import {link} from 'svelte-spa-router' 
</script>

<h1>showpage</h1>
<a href="/" use:link>Homeへ</a>
起動してみる
$ npm run dev
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away