Commit 09f03827 authored by Clément's avatar Clément

Merge branch 'feature/#18-keep-url' into 'master'

update: keep-url attribute #18

See merge request !9
parents a76fd57b e6bce54f
Pipeline #2594 passed with stage
in 27 seconds
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>SIB test: sib-router</title>
<script type="module" src="../src/index.js"></script>
<style>
sib-router {
display: block;
text-align: center;
}
sib-route,
sib-link {
display: inline-block;
padding: 0.5em;
margin: 0.2em;
background-color: #ccc;
cursor: pointer;
}
[active]{
background-color: #afa;
}
</style>
</head>
<body>
<sib-router default-route="page1" use-hash keep-url>
<sib-route name="page1">1st page</sib-route>
<sib-route name="page2">2nd page</sib-route>
<sib-route name="page3">3rd page</sib-route>
</sib-router>
<div id="page1" hidden>
<h1>Page 1</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Reiciendis,
commodi.</p>
<sib-link next="page2">page 2 ></sib-link>
</div>
<div id="page2" hidden>
<h1>Page 2</h1>
<p>Quos, suscipit pariatur! Nulla fugiat excepturi pariatur fuga delectus
corrupti.</p>
<sib-link next="page3">page 3 ></sib-link>
</div>
<div id="page3" hidden>
<h1>Page 3</h1>
<p>Rem, veniam repudiandae! Error repudiandae sapiente blanditiis natus
libero tenetur.</p>
</div>
</body>
</html>
......@@ -24,6 +24,7 @@
<li><a href="examples/basic.html">basic</a></li>
<li><a href="examples/sub-menu.html">sub-menu</a></li>
<li><a href="examples/no-route-name.html">no-route-name</a></li>
<li><a href="examples/keep-url.html">keep-url</a></li>
</ul>
</body>
</html>
......@@ -58,11 +58,13 @@ export default class SIBRouter extends HTMLElement {
const path = route.getPath(this.prefix, routeName, id)
//update current URL
this.display(routeName, resource);
if(this.hasAttribute('keep-url')) return;
if(this.useHash)
window.location.hash = path;
else
history.pushState({}, routeName, '/' + path);
this.display(routeName, resource);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment