tibi-svelte-starter/src/components/App.svelte

48 lines
1.1 KiB
Svelte
Raw Normal View History

2021-03-22 15:59:05 +01:00
<script lang="typescript">
2021-09-14 13:26:35 +02:00
import { Router, Route, links } from "svelte-routing"
2021-03-22 15:59:05 +01:00
import { scrollToTop } from "svelte-scrollto"
import { location } from "../store"
2021-09-13 18:12:40 +02:00
import Content from "./routes/Content.svelte"
2021-03-22 15:59:05 +01:00
export let url = ""
if (url) {
// ssr
let l = url.split("?")
$location = {
path: l[0],
search: l.length > 1 ? l[1] : "",
categoryPath: l[0].replace(/\/\d{4,99}[^\/]+$/, ""),
push: false,
pop: false,
}
}
// scroll to top on new site
location.subscribe((l) => {
if (l.push) scrollToTop()
})
if (typeof window !== "undefined") console.log("App initialized")
</script>
2021-09-13 18:12:40 +02:00
<style lang="less" global>
@import "./../css/main.less";
h1 {
color: red;
}
</style>
<h1>__PROJECT_TITLE__</h1>
2021-09-14 13:26:35 +02:00
<div use:links>
2021-09-13 18:12:40 +02:00
<a href="/test1">1</a>
<a href="/test2">2</a>
<a href="/test3">3</a>
<a href="/test4">4</a>
<Router url="{url}">
<Route path="/*path" let:params>
<Content path="/{params.path}" />
</Route>
</Router>
2021-09-14 13:26:35 +02:00
</div>