Repository navigation
Description
I'm submitting a ... (check one with "x")
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
In the case of such router config with ContainerComponent consuming empty path:
const routes = [
{
path: '',
component: ContainerComponent,
children: [
{ path: 'a', component: AComponent },
{ path: 'b', component: BComponent },
]
}
];
and ContainerComponent having relative links to children in template:
<a [routerLink]="['a']">Link to A</a> (or <a [routerLink]="['./a']">Link to A</a>)
<a [routerLink]="['b']">Link to B</a>
RouterLink directive generates incorrect links when user navigated to one of the child component. F.e. if user went to /a route, links would be like that: /a/(a) and /a/(b).
Expected behavior
Relative links should be generated properly: /a and /b.
Minimal reproduction of the problem with instructions
http://plnkr.co/edit/Lf2Vfe?p=preview
Click on any link. Then you could see that links rendered in AppComponent are correct, but not the ones in ContainerComponent (they both look like /a/(a) and /a/(b)).
What is the motivation / use case for changing the behavior?
Please tell us about your environment:
- Angular version: 2.2.1
- Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
-
Language: [all | TypeScript X.X | ES6/7 | ES5]
-
Node (for AoT issues): 4.2.1
Activity
DzmitryShylovich commentedon Nov 22, 2016
http://plnkr.co/edit/fYck0CbiXrPKszbMo4eW?p=preview
dubadub commentedon Nov 22, 2016
@DzmitryShylovich Yeah, absolute paths work just fine. Problem comes when used relative path. It's necessary to use relative path for example in case of reusable module with own navigation bar and which is connected to components tree on quite deep level. It's not very handy to provide variable with path from the root.
DzmitryShylovich commentedon Nov 22, 2016
https://angular.io/docs/ts/latest/guide/router.html#!#relative-navigation
dubadub commentedon Nov 22, 2016
It seems to me that I did everything right according to docs. Maybe I missed something. But... @DzmitryShylovich Did you manage to see that links look like
/a/(a)and/a/(b)wKoza commentedon Nov 22, 2016
If you want to use relative path, you should change your router configuration. http://plnkr.co/edit/xA2S46bMNg5ZgFa5XbNM?p=preview
buctwbzs commentedon Nov 24, 2016
i think you maybe missed something.read docs,you will get it .
vicb commentedon Dec 1, 2016
sounds like a legit bug
klinki commentedon Jan 12, 2017
I have the same problem. It still doesn't work properly in templates.
leon commentedon Jan 23, 2017
I have the same problem.
It looks like the router doesn't resolve urls which either don't have a path, or are abstract paths (no component).
When I'm in a category and try to link up one level with
I'm still getting
/en/1instead of/enI've iven tried doing it from the Category Component with the same result
furcino commentedon Feb 20, 2017
Hello, I have the same problem. If there is a route localhost/parent/child and I have a
[routerLink]="[../sibling]"link, it creates the url localhost/parent/child/sibling instead of localhost/parent/sibling.The only way to get the desired behavior is to use absolute links, which is undesirable with standalone modules.
The problem occurs only if I use a module with links to sub-modules. For example an authorization module with a login module, sing up module etc. I can not link from the sign up module to the login module without using absolute links. If I change the routing to only use the components (LoginComponent, RegisterComponent) and all these are accessible from the authorization module, the relative links work.
ytilis commentedon Mar 21, 2017
Can confirm that we're seeing the same issue as @leon with pathless routes breaking relative routerLink calls. Adding a path value fixes it, so it's definitely a bug. Using absolute paths for now until this is resolved.
anantkamath commentedon Apr 26, 2017
I'm facing this issue too (angular 2 final release)
50 remaining items
fix(router): Fix relative link generation from empty path components (#…
fix(router): Fix relative link generation from empty path components (a…
angular-automatic-lock-bot commentedon Jul 10, 2020
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.
fix(router): Fix relative link generation from empty path components (a…