crisward / riot-routehandler

An angular-ui style minimalist route handler for riot.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

combination "/"+tag routing and "/foobar"+middleware routing

coderofsalvation opened this issue · comments

@crisward hey I discovered interesting behaviour:

When i setup a combination of two tag-routings + 1 middleware routing:

{ route:"/", tag:"home" },
{ route:"/another", tag:"foo" },
{ route:"/foobar", use: middlewarefunc }

Then after running a middleware-routing, it seems the riot-routehandler needs one click on another tag-routing, before being able to proceed normally.

Because

  1. riot-routehandler will open <home> by default
  2. then when clicking the middlewarefunc /foobar, it will open something else..as expected.
  3. unfortunately, after that, when '/' is being clicked..nothing happens.
  4. then..only after clicking on '/another' tag-routing ..clicking on '/' will open <home> again as expected.

Any clue?

I'll try and take a look at this over the weekend. Next is only called for default routes, ie nested routes which are just a /. It uses filter to check if this route exists in the sub-routes. If you've got sample code, or could add failing test that could be really useful.

Thanks.

Good news :) I could replicate the problem here:

http://codepen.io/anon/pen/OMJRXV

now click:

  1. Middleware
  2. Page 2
  3. Middleware
  4. Page 2

You'll notice that at step 4 you'll still be watching the Middleware tag.
Oddly enough Page 1 seems to work all the time.

scenario: I need to set a tag dynamically after a link is clicked, and populate it with data after riot mounted the tag. Page.redirect() is not sufficient for me, hence setTags seemed quite convenient to do the job.

It seems to be the route firing straight after the middleware, but only every other click. I've found it not working on either. I'll try and turn this into a breaking test, and push the solution when I have one.

The problem was, the routehandler doesn't re-mount already mounted tags. When you navigate to a new tag, the old tag is unmounted. However if you navigated to middleware no un-mounting occurred. So the router thought it was already mounted and didn't mount it again. Hence the issues. The router will now unmount a tag when you navigate to your middleware route, unless the middleware is a wildcard '*'.

Not sure I've every used the word 'mount' so often in paragraph...

I've checked your codepen and it now works as expected.
If you close this issue I'll push a patch to npm.

hehe agreed, I feel like a mountingpoint myself after seeing all those 'mount's :)
Thx just returned from a night out with friends.
Gotta do family stuff tomorrow, but after that I'll test the patch.
Going Zzzzz now.

As I've now pushed the fix I'll close this, let me know if you're still having problems.