Skip to content

Access URL containing hash directly with HTML5Mode on #2134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hugsbrugs opened this issue Jul 27, 2015 · 1 comment
Closed

Access URL containing hash directly with HTML5Mode on #2134

hugsbrugs opened this issue Jul 27, 2015 · 1 comment

Comments

@hugsbrugs
Copy link

Hi everybody !

Here is my headache of the day : Using ui-router 0.2.15, angular 1.3.17, HTML5Mode is activated, Apache .htaccess relevant part is :

<ifModule mod_rewrite.c>
    RewriteEngine On

    # REDIRECT HTTP TO HTTPS
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.my-website.com/$1 [R,L]

    # REDIRECT ALL NON-WWW TO WWW
    RewriteCond %{HTTP_HOST} ^my-website.com
    RewriteRule (.*) https://www.my-website.com/$1 [R=301,L]

    # FOR ANGULAR -> redirect everything to index.html except directories api & assets & admin
    RewriteRule ^(api|assets|admin)($|/) - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !index
    RewriteRule (.*) index.html [L]
</ifModule>

I can navigate between different states using :

$state.go(my_state, {'#':my_hash});

hash is correctly appended to url and with this HTML :

<div ui-view autoscroll="true"></div>

and javascript config block :

$uiViewScrollProvider.useAnchorScroll();

run block

$anchorScroll.yOffset = 80;/* because of a fixed bootstrap navbar, I need an offset */

the router automatically scrolls to my element with id="my_hash"

So everything would be perfect IF I could access my states when doing a page refresh or a direct access to an URL like :
https://www.my_website.com/my_state_url_path#my_hash

when I do so, everything which is after # is removed from the URL. I'm pretty sure it doesn't come from .htaccess.

Is there any declaration to do in state definition to make it works ? Does it works out of the box for you ? Thanks for any suggestions !

Hugo

EDIT
It is now sure it comes from my router's config because doing a simple :
https://www.my_website.com#hello
keeps the "hello" so I have to precise I'm using nested states and now believe hash is lost between state transition ... and seems to be linked to #510

@eddiemonge
Copy link
Contributor

Closing as a duplicate of #510 since it does seem to be the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants