crisward / riot-routehandler

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Url with anchor

rodmar35 opened this issue · comments

Hello,

Thanks a lot for this router !

I try to use url with anchor like /#!/page2#toto to move directly at the content inside a page/tag.
But it's always the content of 404 that is display (page1 by default in the router)

It's the same result with parameter in url like /#!/page2?toto=test

Any idea ?
Thanks
Rodmar35

If you use hash routing, you've already used your hash/anchor.

You could probably use

/#!/page2/part1

The setup part as a param, ie (this is not tested, not sure about the scroll syntax being correct)

var routes = [
    {route:"/",tag:"home"},
    {route:"/page2/:part",tag:"page2"}
    ]}
  ];
The in your tag. 

this.on('mount',function(){
  if(opts.params.part){
    this.scrollto(opts.params.part) // use this to scroll to something with js 
  }
});

this.scrollto = function(part){
  var elem = document.getElementById(part)
  if(elem){
    window.scrollTop = document.getElementById(part).getBoundingClientRect().top
  }
}

Thank you for your answer.
You're right this works with hashbang:false

I have another issue.
When i click on the page link, i can see the page2. But when i try to acces directly from url bar (mydomain.com/riot-route/page2/ the server can't find it.

I try the option "page.base" without succes.

Any idea ?

For information I try to work together Riotjs, your router and FullPageJs (http://alvarotrigo.com/fullPage/).
I can mount the main tag with a fullPageJs slider but it's impossible to "change tag" / route with a new on slider. I'll try to post an example quickly.

Thanks a lot in advance

Thanks in advance

You need to get your webserver to deliver the app from all the urls in your router. This varies depending on what backend you're using.

If you're using apache, a .htaccess file should do it. Check out mod_rewrite. You'll want to rewrite all routes to load your index.html file. Though you'll need to use a regex so you don't match images and resources etc.

Node, Python, Ruby, PHP etc will also have methods of doing this via a server side router. If you let me know what you're using on the server side I may be able to help more. But your answer is probably already available on stack overflow.

I'll close this now as I think the question has been answered.