Comments (12)
I am also curious, if I want to achieve my goal, how should I change the code? Thanks!
from route.
Hi @txchen, good question!
v2.3 has introduced filter. So now we can write down like this:
function showNews(id) {
if (!id) id = 1
require('./views/news-view.html')
loadView('news-view', id)
}
riot.route('/', showNews)
riot.route('/news/*', showNews)
riot.route.start()
riot.route.exec()
If you use this in the tag, it would be better to use sub-router:
var subRoute = riot.route.create()
subRoute('/', showNews)
subRoute('/news/*', showNews)
See more why we use sub-router, FYI.
from route.
@cognitom Thanks! But I am afraid this is not what I want.
My requirement is: is no path, then change the path to some default value. (/#news/1 for example)
Your code seems not changing the route. Or I missed some points?
from route.
FYI, actually I am trying to change my code to use riot 2.3, the existing one is: https://github.com/txchen/riot-hn/blob/gh-pages/src/app.html
It is now working well with 2.2.4. Now I want to make it using latest riot and router :)
from route.
I see, you mean redirecting to another path.
You could use riot.route('news/1')
, I think. Doesn't work fine?
from route.
Yes, it changes the url. However, the callback function is not executed after url is changed, thus, the actual mounting logic does not happen.
That's why I asked: is changing route supported inside routing callback logic?
from route.
Yeah, should be. I'll check it soon, after lunch. Wait a few hours.
from route.
Thanks a lot! @cognitom
I think you can take a look at https://github.com/txchen/riot-hn/blob/gh-pages/src/app.html
I'd like to make it continue to work in 2.3
from route.
@txchen I'm still working on it. It seems the behaviour of history.pushState
. I'll look into more deeply.
from route.
Done! I've found the reason, finally.
observable
doesn't allow trigger()
on the same callback. To avoid this, I've added the stack in emit function. But a bit awkward.
Could you have a look at this? #23 @txchen @GianlucaGuarini
Thanks.
from route.
Yeah, a little bit awkward :)
I realized that I can workaround my issue by explicitly call my actual functional logic:
studyRoute(view, id) {
switch(view) {
case 'news':
require('./views/news-view.html')
self.loadView('news-view', id)
break
default:
riot.route('news/1')
self.loadView('news-view', 1) // because I know here changing url will not trigger callback.
}
}
Not sure if this worth a fix to increase lib size, maybe my usage is not that common. You guys can decide.
from route.
Ok, merged to master.
You could remove that line, after v2.3.1 ;-)
Thank you for your continuous contribution!
from route.
Related Issues (20)
- Router fails entirely when not in index of a folder HOT 1
- When trying to put a component inside a route it is not mounted. HOT 4
- Import route / router fails on Edge after rollup bundler HOT 4
- Using router with rollup causes error HOT 1
- Infinite loop when child is directly nested in route HOT 1
- Child component onUpdated not firing
- Exclude path from routing HOT 2
- Route function rather than Update HOT 1
- How to catch "404 Not Found" routes properly? HOT 3
- "Maximum call stack size exceeded" error and a component inside route component are mounted multiple times
- Bug in support of 'target' attribute HOT 3
- Disable setting history. HOT 3
- Can't get routes with parameters to work HOT 1
- use decodeURI() on route HOT 5
- setBase is working? HOT 1
- Download a file HOT 2
- Error when compiling webpack HOT 3
- Updating component on route change HOT 3
- Router captures all links regardless of base path HOT 3
- Route slots are multiplying after each route change HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from route.