Storeon router module
See original GitHub issueIn 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:
- Created 4 years ago
- Reactions:2
- Comments:18 (18 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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?
@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.