Skip to content
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

add "currentUri" to application controller #4963

Closed
ilovett opened this issue May 30, 2014 · 5 comments
Closed

add "currentUri" to application controller #4963

ilovett opened this issue May 30, 2014 · 5 comments

Comments

@ilovett
Copy link

ilovett commented May 30, 2014

Would be fantastic if you could some how build a url based on the currentPath... from within that function... Does a reverse look up of the model for controller and fills in the dynamic url pieces

Ember.Router.map(function() {
    this.route('index', { 'path' : '/' });
    this.resource('translation', { 'path' : '/t' }, function() {
        this.route('index', { 'path' : '/:translation_hash' });
    });
});

Ember.Router.reopen({
    'location' : (GLOBALS.location) ? GLOBALS.location : 'history',
    'onTransition' : function() {
        console.log(this.get('router.reverseUrl'));
        // "/t/cXwsd5"
    }.on('didTransition')
});

Why? Running apps on Phonegap / Cordova you will quickly find that "window.location" don't work so well... nah mean?

@ilovett
Copy link
Author

ilovett commented Jun 1, 2014

Looking further into on('didTransition') I see that I can actually access the current url, even if the router location is set to none...

    'onTransition' : function() {
        App.LOG.info('router.js didTransition: '+this.get('url'));
        // "/t/cWsd5"
    }.on('didTransition')

What would be nice is if I could access "controllerFor" from here...

this.controllerFor('application').set('currentUri', this.get('url'));

OR better yet if Ember just decided to throw currentUri on the application controller, as a sibling next to currentPath

As an example of why this is useful, say you want to share a link, but you are running within a Phonegap/Cordova wrapper... it would be as easy as

shareUrl = 'http://example.com' + this.get('controllers.application.currentUri');

@ilovett ilovett changed the title route reverse url add "currentUri" to application controller Jun 1, 2014
@rwjblue
Copy link
Member

rwjblue commented Jun 1, 2014

@machty - Thoughts on this one? Seems like a straightforward change, but at this point with three props being set maybe we are missing a higher abstract piece...

@ilovett
Copy link
Author

ilovett commented Jun 2, 2014

I can understand not wanting to give access to the entire router from controllers, but there are some things in the router controllers may need to access

@wagenet
Copy link
Member

wagenet commented Nov 1, 2014

@machty never got your input here.

@sandstrom
Copy link
Contributor

I think it's safe to close this issue in favour of the RFC on a routing service: emberjs/rfcs#38

@ilovett Feel free to close this issue.

It isn't solved, but the RFC would be the right place to continue the discussion.

@ilovett ilovett closed this as completed Nov 18, 2015
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

4 participants