This is a project template for Svelte Single Page Application. It lives at https://github.com/AlexxNB/svelte-template-spa.
It is based on template and svelte-router as a router.
To create a new project based on this template using degit:
npm install -g degit # you only need to do this once
degit AlexxNB/svelte-template-spa svelte-spa
cd svelte-spa
Note that you will need to have Node.js installed.
You can define routes in routes.js
file:
// Import all necessary view components here
import Home from './views/Home.html'
import About from './views/About.html'
export default{
// hash - will handle URLs like localhost:8080/#/sub1/sub2
// history - common URLs like localhost:8080/sub1/sub2
// Note: On production server you should manually set rewrite all requests to index.html
mode: 'history',
// Each route should have imported component from views directory
routes: {
'/': Home,
'/about': About
}
}
Install the dependencies...
cd svelte-spa
npm install
...then start rollup development server:
npm run dev
Navigate to localhost:8080. You should see your app running. Edit any file in src
, save it, and the page should reload with your changes.
npm run build
Then all you builded SPA files will be in dist
directory.