Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

HTML5Mode - User Session Handling Does Not Work On Manual URLs #206

Closed
iq-dot opened this issue Oct 13, 2014 · 3 comments
Closed

HTML5Mode - User Session Handling Does Not Work On Manual URLs #206

iq-dot opened this issue Oct 13, 2014 · 3 comments

Comments

@iq-dot
Copy link

iq-dot commented Oct 13, 2014

Hi Guys,

I have an issue where I have turned on HTML5Mode:

$locationProvider.html5Mode(true).hashPrefix('!');

And also the Express re-write:

// Setting the app router and static folder
app.use(express.static(path.resolve('./public')));

// Globbing routing files
config.getGlobbedFiles('./app/routes/**/*.js').forEach(function(routePath) {
    require(path.resolve(routePath))(app);
});

// For HTML5 Mode URL routing
app.all('/*', function(req, res, next) {
    res.render('index');
});

The problem I have is that the site works fine if navigating URLs within it, however if I am logged in and manually enter the URL on the browser e.g. '/settings/profile' then it does not recognise that the user is logged in, however if I go back to the homepage '/' then it recognises the user is logged in.

Doing some debugging it seems the Authentication.user gets unset, however going back to the '/' something sets it again and it will only stay set if navigating via the site only and not entering URLs on the browser.

This code here on the 'Authentication' service:

_this._data = {
user: window.user
};

And this is on the layout.server.view.html (back-end template).

<script type="text/javascript">
    var user = {{ user | json | safe }};
</script>

I guess it seems the above code in layour.server.view is not run due to the full page refresh, while having the hashbang mode, even if you type a URL in the browser, it does not cause a page refresh.

Surely it must be easier to use pretty URLs in HTML5 Mode without the above issues? I can not be the only one who wanted this?

Can anyone suggest what I could be doing wrong here and how I might be able to get it to work with HTML5Mode? I don't get this issue if using the default hashbang mode.

See this SO question for more info:

http://stackoverflow.com/questions/26309107/angularjs-best-way-to-handle-state-on-manually-entered-urls

@rhutchison
Copy link
Contributor

Did you look at my PR #195?

@iq-dot
Copy link
Author

iq-dot commented Oct 14, 2014

No, I haven't thanks for that, let me check it out

@iq-dot
Copy link
Author

iq-dot commented Oct 14, 2014

Worked like a charm, thanks

@iq-dot iq-dot closed this as completed Oct 14, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants