question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Storeon router module

See original GitHub issue

In SPA applications, you often need to interact with the url. One approach is to treat the url as part of the state. When changing state, changing the url and Vice versa.

I suggest adding an optional router module to Storeon. For example so:

import createStore from 'storeon'
import createRouter from 'storeon/router'

const router = createRouter();
export const store = createStore([/* ... */, router])

store.on('router/change', () => {
  // On url changed
})

// Set new url
store.dispath('router/push', '/ololo/')

It is very easy to use in React:

import useStoreon from 'storeon/react'

export default function Counter() {
  // Counter will be re-render only on `state.count` changes
  const { url } = useStoreon('router')

  switch(url) {
    case '/':
      return <IndexPage />

    case '/about':
      return <AboutPage />
  }

  return <p>Not Found</p>
}

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:18 (18 by maintainers)

github_iconTop GitHub Comments

4reactions
aicommented, Apr 29, 2019

storeon/storeon was moved. npm org was also created.

Storeon will continue to use storeon package name, but the router will use @storeon/router. Is it OK?

Any suggestion about router API?

0reactions
majo44commented, Jun 5, 2019

@ai I putted clean router code here https://github.com/majo44/storeon-async-router, let me finish it (test, documentation, ect.) and later you can decide to move it to @storeon scope, or I will leave it on separate repo.

Read more comments on GitHub >

github_iconTop Results From Across the Web

storeon/router: Storeon module for URL routing - GitHub
Storeon Router solves the problems of routing while seamlessly providing full control. Its size is 577 bytes (minified and gzipped) and uses Size...
Read more >
24. Router store - Angular and NgRx - GitBook
In this section we will use NgRx's router store library to listen to url or router events as actions in our effects.
Read more >
Top 5 @ngrx/router-store Code Examples - Snyk
To help you get started, we've selected a few @ngrx/router-store examples, based on popular ways it is used in public projects.
Read more >
Router-store in NgRx | Use of router-store in Angular - YouTube
Router - store in ngrx can be used as bindings to connect the Angular Router with Store. Multiple actions are dispatched during each...
Read more >
@ngrx/router-store - npm
Bindings to connect @angular/router to @ngrx/store. Latest version: 15.1.0, last published: 8 days ago. Start using @ngrx/router-store in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found