Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Support routing directly to a component #425

Closed
sethladd opened this issue Jan 22, 2014 · 23 comments
Closed

Support routing directly to a component #425

sethladd opened this issue Jan 22, 2014 · 23 comments
Milestone

Comments

@sethladd
Copy link
Contributor

My views are simple, they just have a single custom component. I'd much rather route directly to a component, and remove the view altogether.

ex:

components/
  thing.dart
  thing.html
views/
  thing.html

thing.html:

<thing></thing>
@ghost ghost assigned pavelgj Jan 22, 2014
@pavelgj
Copy link
Contributor

pavelgj commented Jan 22, 2014

@sethladd Are you thinking something like this?

    router.root
      ..addRoute(
          name: 'foo,
          path: '/foo',
          enter: view(component: 'my-component')

or more generic?

    router.root
      ..addRoute(
          name: 'foo,
          path: '/foo',
          enter: view(html: '<my-component></my-component>')

@shailen
Copy link

shailen commented Jan 23, 2014

How about something like this?

  router.root
      ..addRoute(
          name: 'foo,
          path: '/foo',
          enter: component('my-component')

@sethladd
Copy link
Contributor Author

Either view(component: 'my-component') or component('my-component') or probably better yet: component(MyComponent)

I like the last one, because strings are hard to get right (no static analysis)

@sethladd
Copy link
Contributor Author

BTW if we can get this, it is a huge win for ease of use. Thanks for considering!

@pavelgj
Copy link
Contributor

pavelgj commented Jan 24, 2014

I'm actually looking into different angular specific route definition DSL. Early draft:

 view.configure(router, {
   'foo': ngRoute(
       path: '/foo',
       view: 'foo.html',
       mount: {
         'bar': ngRoute(
             path: '/bar',
             component: 'bar-component',
             defaultRoute: true
         ),
         'baz': ngRoute(
             path: '/:baz'
         )
       }
   ),
   'qux': ngRoute(
       path: '/qux',
       view: 'qux.html'
   )
 });

@shailen
Copy link

shailen commented Jan 24, 2014

I like component('my-component') and component(MyComponent) but prefer the former because it is more consistent with how routes generally seem to be specified.

@pavelgj
Copy link
Contributor

pavelgj commented Jan 24, 2014

Actually, I thought about it more, and it seems like component('my-component') is not really possible. The reason is because components can be defined with arbitrary selector, including attribute/content selector. Components are not always "custom tags". For example: foo[bar=baz].

component(MyComponent) would be the preferable way to do it, however currently there is no way in angular.dart to create "a new instance of a given component".

The first iteration will probably have to be view.html('<my-component></my-component>') or view.html('<foo bar="baz"></foo>') or in the new DSL viewHtml: '<foo bar="baz"></foo>'

@bgourlie
Copy link
Contributor

@pavelgj Can you create an issue regarding the route definition DSL you're looking into? I have some feedback but don't want to go off-topic in this issue.

@pavelgj
Copy link
Contributor

pavelgj commented Jan 24, 2014

@bgourlie #435

@sethladd
Copy link
Contributor Author

view.html('<my-component></my-component>') should be sufficient. I didn't realize Angular Components can have non-element-name selectors.

Thanks, really looking forward to it.

@jbdeboer
Copy link
Contributor

@sethladd @pavelgj Is #435 good enough to close this issue?

@jbdeboer jbdeboer modified the milestones: 0.9.8, v0.9.7 Feb 10, 2014
@pavelgj
Copy link
Contributor

pavelgj commented Feb 10, 2014

Not really, this is a separate feature. #435 was a prerequisite.

@sethladd
Copy link
Contributor Author

This works, thanks!

@chirayuk chirayuk modified the milestones: v0.9.9, 0.9.8 Feb 19, 2014
@matsko matsko modified the milestones: 0.9.10, v0.9.9 Mar 10, 2014
@vicb vicb modified the milestones: 0.11.0, 0.10.0 Mar 20, 2014
@chalin
Copy link
Contributor

chalin commented Mar 25, 2014

This still in the works?

@pavelgj
Copy link
Contributor

pavelgj commented Mar 26, 2014

Yes, it's still being considered. It's just not as simple as it seems -- it makes expression extractor a bit more complicated.

@mhevery
Copy link
Contributor

mhevery commented Apr 9, 2014

@pavelgj Can you work on this or should I find someone else?

@pavelgj
Copy link
Contributor

pavelgj commented Apr 10, 2014

@mhevery This requires changes to the expression extractor transformer, so it's a bit more work than I expected. I can work in this, but it's not very high on my todo list (next week?).

@michalpie
Copy link

Specifying view html for a route will be a great feature we badly lack. It will allow not only to specify a component, but also to pass attributes to it. Currently we have to use a workaround described by me here: #837, which is not correct as it causes ng-view to be reevaluated each time, even if not needed.

pavelgj added a commit to pavelgj/angular.dart that referenced this issue Apr 16, 2014
pavelgj added a commit to pavelgj/angular.dart that referenced this issue Apr 16, 2014
@vicb vicb modified the milestones: 0.10.0, 0.9.11 Apr 16, 2014
@pavelgj
Copy link
Contributor

pavelgj commented Apr 16, 2014

@mhevery, please take a look at PR #908

@pavelgj
Copy link
Contributor

pavelgj commented Apr 17, 2014

This is now implemented. You can route to an inline template (viewHtml). Ex:

    views.configure({
      'foo': ngRoute(
          path: '/foo',
          viewHtml: '<foo-component></foo-component>')
    });

@sethladd
Copy link
Contributor Author

Thanks!

@kemallette
Copy link
Contributor

It was a treat cleaning out a bunch of extra view files today. Thanks for the hard work everyone! :)

@michalpie
Copy link

Thanks a lot - we have updated our code to use the new feature and it works perfectly.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging a pull request may close this issue.