Is there really no way to make an extra dynamic segment in Ember?

I tried to add a dynamic segment, which should be optional for my application, firstly, I did not know that they could not be optional with the syntax: param, and I started to get a strange not descriptive error from my templates of all things

Uncaught TypeError: Cannot read property 'shouldSupercede' of undefined 

It took me more than an hour to understand what was happening, and no matter how I tried to make the parameter optional with the * param and (: param) parameter, but I could not.

This is a huge problem. If someone knows the right way to do this, I will be very grateful

+1
source share
2 answers

You can use nested resources (verified with version 1.8.1):

 this.resource('profile-root', { path:'/profile' },function(){ this.resource('profile', { path : ':id' }); }); 

Therefore, when you go to "/ profile", it will use this route:

  • Root profile
    • Profile root.index

And when you go to / profile / 1:

  • Root profile
    • Profile
      • profile.index
+3
source share

A nested route will provide you with an optional segment. This is the way it was at Amber. Keep in mind that this depends a lot on what you want your application to really do when it gets to the routes in question.

I suggest that you read the routing guide completely and follow the video on the ember main site to really feel what the ember route is and how it differs from what you may have encountered before.

A simple point in the case: Routes are responsible for loading data and can be used to store actions, while in other frameworks they really are not.

[edit]

In addition, queryParams or globbing paths (using the splat "*" char) may be more related to what you are trying to do.

0
source share

All Articles