Skip to content

Commit 9799b67

Browse files
committed
simple router based on this comment sveltejs/svelte#238 (comment)
1 parent e4b7082 commit 9799b67

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

src/App.html

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<header>
22
<h1>Admin Website</h1>
3+
34
<nav>
4-
<ul>
5-
<li><Link to='/doctors'>Doctors</Link></li>
6-
{{#if user2.loggedIn}}
7-
staus: logged in
8-
<li><a href='' on:click='logout()'>Logout</a></li>
9-
{{else}}
10-
status: logged out
11-
<li><Link to='/login'>Login</Link></li>
12-
{{/if}}
13-
</ul>
5+
{{#if route()=== '/login'}}
6+
<Login user='{{user2}}'/>
7+
{{elseif route() === '/'}}
8+
<Home/>
9+
{{elseif route() === '/doctors'}}
10+
<Doctors/>
11+
{{elseif route() === '/about'}}
12+
<About/>
13+
{{/if}}
1414
</nav>
1515
</header>
1616

@@ -25,45 +25,31 @@ <h1>Admin Website</h1>
2525
</style>
2626

2727
<script>
28-
import createRouter from './services/createRouter';
2928
import Login from './components/Login.html';
3029
import Home from './components/Home.html';
3130
import About from './components/About.html';
3231
import Doctors from './components/Doctors.html';
3332
import Link from './components/Link.html';
3433

35-
const router = createRouter({
36-
'/': Home,
37-
'/home': Home,
38-
'/login': Login,
39-
'/doctors': Doctors,
40-
'/about/:name': About,
41-
});
42-
4334
export default {
4435
data () {
4536
return {
4637
user2: {loggedIn: false}
4738
}
4839
},
4940
onrender() {
50-
router.start(window.location, window.document.querySelector('#content'));
51-
const user = localStorage.getItem('user');
52-
if(user) {
53-
this.set({ user2: {loggedIn: true} });
54-
return;
55-
}
41+
console.log(window.location.pathname);
5642
},
5743

5844
onteardown() {
59-
router.teardown();
6045
},
6146

6247
components: {
6348
Login,
6449
Link,
6550
Home,
6651
About,
52+
Doctors,
6753
},
6854

6955
methods: {
@@ -72,6 +58,11 @@ <h1>Admin Website</h1>
7258
localStorage.removeItem('user');
7359
this.set({ user2: {loggedIn: false} });
7460
}
61+
},
62+
helpers: {
63+
route () {
64+
return window.location.pathname;
65+
}
7566
}
7667
}
7768
</script>

0 commit comments

Comments
 (0)