Giter Site home page Giter Site logo

svelte-router's Introduction

Hi there, I'm 鐧界啽! 馃憢

github contribution grid snake animation

javascript logo typescript logo react logo vuejs logo rust logo

svelte-router's People

Contributors

beesperester avatar grumpytim avatar jikkai avatar robbrazier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

svelte-router's Issues

'active' class on the Link

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.

Is there a way to pass data into route components?

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

Example get route param

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.

Trouble compiling with rollup

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:

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)

How does listen work?

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>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    馃枛 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 馃搳馃搱馃帀

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google 鉂わ笍 Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.