jikkai / svelte-router Goto Github PK
View Code? Open in Web Editor NEWRouter component for Svelte
Home Page: https://jikkai.github.io/svelte-router
License: MIT License
Router component for Svelte
Home Page: https://jikkai.github.io/svelte-router
License: MIT License
How would you implement adding an 'active' class to each Link with an href matching the current path? It's hard to build a navigation menu without that.
Hey there!
So i'm kinda new to Svelte js - and am experimenting with using it for a small upcoming project.
Just wondering if there's a trick to getting the store to be passed down to the route
components...?
I'm currently using: "svelte: ^1.47.1"
Store is currently created and passed into the app like so:
index.js (webpack entry):
import App from './app.html';
import { Store } from 'svelte/store.js';
const store = new Store({
animal: 'dog',
sheep: 'baaah',
});
const app = new App({
target: document.body,
store,
});
export default app;
app.html:
<div>
<RouterLink to="/">Home</RouterLink>
<RouterLink to="/welcome">Welcome</RouterLink>
<h1>animal: {{$animal}}</h1>
<div id="app"></div>
</div>
<script>
import { createRouter, RouterLink } from 'svelte-router'
import Home from './home.html'
import Welcome from './welcome.html'
const router = createRouter({
'/': Home,
'/welcome': Welcome
});
export default {
oncreate () {
console.log(this.store.get('animal')); // "dog"
router.create('#app');
},
ondestroy () {
router.destroy()
},
components: {
RouterLink, Home, Welcome
}
}
</script>
home.html:
<h1>home page!</h1>
<script>
export default {
oncreate () {
console.log(this.store.get('animal')); // undefined
},
}
</script>
inside app.html:
<h1>animal: {{$animal}}</h1>
renders as:
<h1>animal: dog</h1>
as expected.
If i try and access:
<div>{{$animal}}</div>
from home.html, i get the following error:
Uncaught TypeError: Cannot read property '_init' of undefined
How to get param from router
<RouterLink to="/doc/123">Document</RouterLink>
How to get param document_id in DocumentDetail component
export default {
mode: 'history',
routes: {
'/': Home,
'/doc': Document,
'/doc/:document_id':DocumentDetail,
default: NotFound
}
}
Thank you.
Right now "createRouter" when exist "create" function also createRouter contain proxy like methods to History.
Hey, maybe I am doing something wrong, but I started by just copy/past the exemple(https://jikkai.github.io/svelte-router/#/guide/basic-usage)
and this Error keeps poping in
Error: 'Link' is not exported by node_modules/svelte-router/lib/svelte-router.js
my version is svelte-router": "^3.0.0-alpha.2"
Thx for the help ! :)
Windows 10, node 6.0.0
Error: Error: 'default' is not exported by node_modules\svelte-router\lib\svelte-router.js
https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module
src\HelloWorld.html (1:7)
1: import SvelteRouter from 'svelte-router'
Using:
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]
svelte-router/blob/master/src/index.js
is different from npm installed node_modules/svelte-router/lib/svelte-router.js
? Investigating...
Using a tilde in an import statement is a webpack specific thing? e.g. import createRouter from '~utils/create-router'
(from https://stackoverflow.com/a/39535907)
I don't see an example. I want to execute a function when a route triggers, for example check if the user is logged in and then if not redirect them to /login?ref=<original-path>
It would be super neat to see svelte-router
become as mature as vue-router
.
One big feature that would be nice is nested routes, much like how vue-router
handles them:
https://router.vuejs.org/guide/essentials/nested-routes.html
Example:
...
routes: {
'/settings': {
children: {
'contact': {
...
}
}
}
}
Or better yet, use the array structure vue-router uses to make it easier to manage and iterate through them wherever necessary.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
馃枛 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 馃搳馃搱馃帀
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google 鉂わ笍 Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.