GithubHelp home page GithubHelp logo

Comments (12)

txchen avatar txchen commented on June 5, 2024

I am also curious, if I want to achieve my goal, how should I change the code? Thanks!

from route.

cognitom avatar cognitom commented on June 5, 2024

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.

txchen avatar txchen commented on June 5, 2024

@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.

txchen avatar txchen commented on June 5, 2024

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.

cognitom avatar cognitom commented on June 5, 2024

I see, you mean redirecting to another path.
You could use riot.route('news/1'), I think. Doesn't work fine?

from route.

txchen avatar txchen commented on June 5, 2024

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.

cognitom avatar cognitom commented on June 5, 2024

Yeah, should be. I'll check it soon, after lunch. Wait a few hours.

from route.

txchen avatar txchen commented on June 5, 2024

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.

cognitom avatar cognitom commented on June 5, 2024

@txchen I'm still working on it. It seems the behaviour of history.pushState. I'll look into more deeply.

from route.

cognitom avatar cognitom commented on June 5, 2024

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.

txchen avatar txchen commented on June 5, 2024

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.

cognitom avatar cognitom commented on June 5, 2024

Ok, merged to master.
You could remove that line, after v2.3.1 ;-)

Thank you for your continuous contribution!

from route.

Related Issues (20)

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.