This repository was archived by the owner on Aug 18, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 8 files changed +72
-39
lines changed
Expand file tree Collapse file tree 8 files changed +72
-39
lines changed Original file line number Diff line number Diff line change @@ -10,9 +10,5 @@ module.exports = {
1010 ]
1111 }
1212 } ]
13- ] ,
14- plugins : [
15- '@babel/plugin-transform-spread' ,
16- '@babel/plugin-proposal-class-properties'
1713 ]
1814}
Original file line number Diff line number Diff line change 1111 <span >Getting Started</span >
1212 <ul >
1313 <li >
14- <Link to =" /guide/basic-usage" replace >Basic Usage</Link >
14+ <Link to =" /guide/basic-usage" >Basic Usage</Link >
15+ </li >
16+ <li >
17+ <Link to =" /guide/passing-props" >Passing Props</Link >
1518 </li >
1619 <li >
1720 <Link to =" /guide/api" >API</Link >
2427 <span >Component</span >
2528 <ul >
2629 <li >
27- <Link to =" /component/link" replace >Link</Link >
30+ <Link to =" /component/link" >Link</Link >
2831 </li >
2932 </ul >
3033 </div >
Original file line number Diff line number Diff line change 1+ # Passing Props
2+
3+ Passing props to route components by using ` props ` .
4+
5+ ## Foo.svelte
6+
7+ ``` html
8+ <h1 >Hello {title}</h1 >
9+
10+ <script >
11+ export let title
12+ </script >
13+ ```
14+
15+ ## App.svelte
16+
17+ ``` html
18+ <div >
19+ <div use:create ></div >
20+ </div >
21+
22+ <script >
23+ import SvelteRouter from ' svelte-router'
24+ import Foo from ' ./Foo.svelte'
25+
26+ function create (node ) {
27+ const router = new SvelteRouter ({
28+ target: node,
29+ routes: [{
30+ path: ' /foo' ,
31+ component: Foo,
32+ props: {
33+ title: ' Foo'
34+ }
35+ }]
36+ })
37+
38+ return {
39+ destroy () {
40+ router .destroy ()
41+ }
42+ }
43+ }
44+ </script >
45+ ```
Original file line number Diff line number Diff line change 1+ <section >
2+ {@html content }
3+ </section >
4+
5+ <script >
6+ import content from ' ../../docs/guide/PassingProps'
7+ </script >
Original file line number Diff line number Diff line change 11import Introduction from './pages/Introduction'
22import Installation from './pages/Installation'
33import BasicUsage from './pages/guide/BasicUsage'
4+ import PassingProps from './pages/guide/PassingProps'
45import API from './pages/guide/API'
56import Link from './pages/component/Link'
67import NotFound from './pages/NotFound'
@@ -14,6 +15,12 @@ export default [{
1415} , {
1516 path : '/guide/basic-usage' ,
1617 component : BasicUsage
18+ } , {
19+ path : '/guide/passing-props' ,
20+ component : PassingProps ,
21+ props : {
22+ foo : 'bar'
23+ }
1724} , {
1825 path : '/guide/api' ,
1926 component : API
Original file line number Diff line number Diff line change 11{
22 "name" : " svelte-router" ,
3- "version" : " 3.0.0-alpha.1 " ,
3+ "version" : " 3.0.0-alpha.2 " ,
44 "description" : " A simple router for Svelte" ,
55 "main" : " lib/svelte-router.js" ,
66 "author" : " Jikkai Xiao <sonne@asaki.me>" ,
3636 },
3737 "devDependencies" : {
3838 "@babel/core" : " ^7.5.5" ,
39- "@babel/plugin-proposal-class-properties" : " ^7.5.5" ,
40- "@babel/plugin-transform-spread" : " ^7.2.2" ,
4139 "@babel/preset-env" : " ^7.5.5" ,
4240 "alius" : " 0.0.1" ,
4341 "babel-eslint" : " ^10.0.2" ,
Original file line number Diff line number Diff line change @@ -29,13 +29,13 @@ class SvelteRouter {
2929 this . $content = null
3030 this . target = typeof target === 'string' ? document . querySelector ( target ) : target
3131 this . routes = routes
32- this . $listener = SvelteRouter . history . listen ( this . handleRouteChange . bind ( this ) )
32+ this . $listener = history . listen ( this . handleRouteChange . bind ( this ) )
3333
34- this . handleRouteChange ( SvelteRouter . history . location )
34+ this . handleRouteChange ( history . location )
3535 }
3636
3737 destroy ( ) {
38- if ( this . listener ) {
38+ if ( this . $ listener) {
3939 this . $listener ( )
4040 this . $listener = null
4141 }
@@ -54,10 +54,11 @@ class SvelteRouter {
5454
5555 if ( matchedRoute && matchedRoute . component ) {
5656 if ( this . $content ) this . $content . $destroy ( )
57- const Component = matchedRoute . component
57+ const { component : Component , props } = matchedRoute
5858
5959 this . $content = new Component ( {
60- target : this . target
60+ target : this . target ,
61+ props
6162 } )
6263 }
6364 }
You can’t perform that action at this time.
0 commit comments