I want to configure route for my angular2 application. My URL needs to be like this:
http://domain_name/constant_value/variable_value/constant_value
The url can be like following examples:
http://localhost/myhouse/floor1/mirror
http://localhost/myhouse/floor1/room1/mirror
http://localhost/myhouse/floor1/room1/bathroom/mirror
Here the routes /myhouse and /mirror are constant. But the middle part can be anything like /floor1 or /floor2/something/something/....
How can i define a route for that in routing module.
const routes: Routes = [
{
path: 'myhouse',
children: [
{
path: ..., //here how do i configure it
children: [
{
path: '/mirror',
component: MirrorComponent
}
]
}
]
}
];
Here the mirror component must be loaded if the url has /mirror at the end of the url if not login component should be loaded.
Mirror will be loaded for the urls shown above. Each mirror component will have different propertise value inside according to the variable part of the url.
For login component url will be like:
http://localhost/myhouse
or
http://localhost/myhouse/floor1
or
http://localhost/myhouse/floor1/bathroom1
I tried wanted to use regex but it seems the regex is not supported for newer version of angular2. If I am wrong on not being able to use regex please kindly point me to that direction with an example. If not please point me to right direction.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…