Skip to main content

Single page application
Ready

This template shows how to build a single page application that uses Duet Header as the main navigation element. When page changes the page title is being announced by Duet Visually Hidden component. Please note that the example below does not represent a real use case.

Hint: Press F on your keyboard to view both templates and components in fullscreen and ESC to exit the fullscreen mode. You can also open the template in a new browser window.


Open in new window
<!DOCTYPE html>
<html class="duet-bg-gradient duet-sticky-footer" lang="fi">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>LähiTapiola</title>
<link rel="stylesheet" href="https://cdn.duetds.com/api/fonts/2.0.4/lib/localtapiola.css" integrity="sha384-5JYmtSD7nykpUvSmTW1CHMoBDkBZUpUmG0vuh+NUVtZag3F75Kr7+/JU3J7JV6Wq" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdn.duetds.com/api/css/2.0.4/lib/duet.min.css" integrity="sha384-Rr9cMsT3WwT/R75uQz7pZhQirbSQeimsnsYyAbtZtCBq+9GjwG1nGkJex1SQhDao" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdn.duetds.com/api/tokens/3.0.4/lib/tokens.custom-properties.css" integrity="sha384-rxTcztOdY2IJ7Qut98AqRJJY5tXpDexWKN6csXh9raZkxudeSn7Ls9VHTrAC5qrs" crossorigin="anonymous" />
<script type="module" src="https://cdn.duetds.com/api/components/6.0.4/lib/duet/duet.esm.js" integrity="sha384-npAfg93f67dYyc4XaUnxB7TW0UBV1GEyN+I8fe+PY7+5hO+wUjrwMYJoeosWtA9x" crossorigin="anonymous"></script>
<script nomodule src="https://cdn.duetds.com/api/components/6.0.4/lib/duet/duet.js" integrity="sha384-ASuQlaQdg38LcGAQFyUSW9ASxK5xTOoo5v5ECWia1cNZ46lq0HyFCTJhv7KNKP/K" crossorigin="anonymous"></script>
</head>
<body>
<duet-visually-hidden id="announce-title" aria-live="polite"></duet-visually-hidden>

<duet-header></duet-header>
<duet-layout>
<div slot="main">
<duet-card>
<duet-heading id="heading" heading-level="h1"></duet-heading>
<duet-paragraph id="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.
</duet-paragraph>
</duet-card>
</div>
</duet-layout>
<duet-footer></duet-footer>

<script>
const pages = {
".": {
title: "Title - Page 1",
heading: "First page heading",
content: `Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.
`
,
link: "First page",
href: ".",
},
"second-page": {
title: "Title - Page 2",
heading: "Second page heading",
content: `Sed ut perspiciatis unde omnis iste natus error sit voluptatem
accusantium doloremque laudantium, totam rem aperiam,
eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae
vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas
sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores
eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est,
qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit,
sed quia non numquam eius modi tempora incidunt ut labore et dolore
magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis
nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut
aliquid ex ea commodi consequatur? Quis autem vel eum iure
reprehenderit qui in ea voluptate velit esse quam nihil molestiae
consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
`
,
link: "Second page",
href: "second-page",
},
"third-page": {
title: "Title - Page 3",
heading: "Third page heading",
content: `At vero eos et accusamus et iusto odio dignissimos ducimus qui
blanditiis praesentium voluptatum deleniti atque corrupti
quos dolores et quas molestias excepturi sint occaecati cupiditate non
provident, similique sunt in culpa qui officia deserunt mollitia animi, id
est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita
distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque
nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas
assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut
officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates
repudiandae sint et molestiae non recusandae. Itaque earum rerum hic
tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias
consequatur aut perferendis doloribus asperiores repellat.
`
,
link: "Third page",
href: "third-page",
},
}

const changePage = (href = ".") => {
document.title = pages[href].title
document.querySelector("#announce-title").innerHTML = document.title
document.querySelector("#heading").innerHTML = pages[href].heading
document.querySelector("#content").innerHTML = pages[href].content
}

header = document.querySelector("duet-header")

header.items = Object.keys(pages).map(key => ({
label: pages[key].link,
href: pages[key].href,
}))

header.addEventListener("duetItemClick", (e) => {
event.detail.originalEvent.preventDefault()
window.history.pushState(event.detail.data.href, {}, event.detail.data.href)
changePage(event.detail.data.href)
})

window.addEventListener('popstate', (e) => {
changePage(e.state)
})

changePage(".")
</script>
</body>
</html>

Integration

To install this template’s dependencies into your project, run:

npm install @duetds/components
npm install @duetds/css
npm install @duetds/fonts

For further guidelines, please see each package’s documentation.



Tutorials

Follow these practical tutorials to learn how to build simple page layouts using Duet’s CSS Framework, Web Components and other features:

Tutorials

Building Layouts

Tutorials

Using CLI Tools

Tutorials

Creating Custom Patterns

Tutorials

Server Side Rendering

Tutorials

Sharing Prototypes

Tutorials

Usage With Markdown

Tutorials

Zeplin


Troubleshooting

If you experience any issues while using a template, please head over to the Support page for more guidelines and help.