Angular2 Nested Routing parent to child ES5 not working - angularjs

Current working on angular2 beta version 6, in this nested routing like parent to child using (EX: /plan/...) future is not working on es5 JavaScript development, but in type script development it's working perfectly
Throwing error: EXCEPTION: Link "["Plan"]" does not resolve to a terminal instruction.
App.js code
var Tabs = [],viewId;
app.AppComponent =
ng.core.Component({
selector: 'app',
template: '<router-outlet></router-outlet>',
directives: [ng.router.ROUTER_DIRECTIVES],
providers: [ng.http.HTTP_PROVIDERS]
})
.Class({
constructor: [ng.router.Router, function(router) {
console.log("1");
router.config([
{ path: '/', redirectTo: ['Home'] },
{ path: '/home', component: app.HomeComponent, name: 'Home' },
{ path: '/plan/...', component: app.planComponent, name: 'Plan' }
]);
}]
});
document.addEventListener('DOMContentLoaded', function() {
ng.platform.browser.bootstrap( app.AppComponent,[ng.router.ROUTER_PROVIDERS]);
});
Plan.js code
app.planComponent =
ng.core.Component({
selector: 'plan-view',
templateUrl: './assets/src/plan/view/plan.html',
directives: [ ng.router.RouterLink, ng.router.ROUTER_DIRECTIVES],
})
.Class({
constructor:[ng.router.Router, function(router){
console.log("2");
router.config([
{ path: '/', redirectTo: ['PlanInfo'] },
{ path: '/planInfo', component: app.planInfoComponent, name: 'PlanInfo', useAsDefault: true }/*,
{ path: '/coverage', component: app.CoverageComponent, name: 'Coverage' },
{ path: '/nonelective', component: app.nonElectiveComponent, name: 'NonElective' },
{ path: '/loans', component: app.loansComponent, name: 'Loans' },
{ path: '/enrollment', component: app.enrollmentComponent, name: 'Enrollment' }*/
]);
}]
});

I think that you should use the ng.router.RouteConfig decorator instead of the router itself. Like this, you will have the same configuration as with TypeScript.
Here is the way to do:
ng.router
.RouteConfig([
{ path: '/', redirectTo: ['Home'] },
{ path: '/home', component: app.HomeComponent, name: 'Home' },
{ path: '/plan/...', component: app.planComponent, name: 'Plan' }
])(app.AppComponent);
(...)
ng.router
.RouteConfig([
{ path: '/', redirectTo: ['PlanInfo'] },
{ path: '/planInfo', component: app.planInfoComponent, name: 'PlanInfo', useAsDefault: true }/*,
{ path: '/coverage', component: app.CoverageComponent, name: 'Coverage' },
{ path: '/nonelective', component: app.nonElectiveComponent, name: 'NonElective' },
{ path: '/loans', component: app.loansComponent, name: 'Loans' },
{ path: '/enrollment', component: app.enrollmentComponent, name: 'Enrollment' }*/
])(app.planComponent);
As a reference, you could have a look at this plunkr: https://plnkr.co/edit/w61Ecbmuj7EfDnsYEHOS?p=info.

Related

How do I render this object in React with React Router?

How do I render this object using react router? I want to render this object in a menu.
{main: 'Main', about: 'About', contacts: 'Contacts', '404': 404}
Refactor it this way:
const menu = [
{ title: 'Main', path: '/main' },
{ title: 'About', path: '/about' },
{ title: 'Contacts', path: '/contacts' },
{ title: '404', path: '/404' }
];
Now do this in your JSX wherever you want your menu:
{menu.map(item => <Link to={item.path} alt={item.title} />)}
Don't forget to import Link:
import { Link } from 'react-router-dom'

Angular 4.X: Initialize child components router

i have the following app route configuration:
const routes: Routes = [
{loadChildren: './modules/faq/faq.module', path: 'faq'},
{loadChildren: './modules/pagination/pagination.module', path: 'page'},
{loadChildren: './modules/appointmentAgreement/appointmentAgreement.module#AppointmentAgreementModule', path: 'terminvereinbarung'}
];
And the appointmentAgreement child modules route configuration
const appointmentAgreementRoutes: Routes = [{
path: '',
children: [
{path: 'thema', component: TopicSectionComponent},
{path: 'filiale', component: BranchSectionComponent},
{path: 'termin', component: DatetimeSectionComponent},
{path: 'daten', component: PersonalDataSectionComponent},
{path: 'bestaetigung', component: ConfirmationSectionComponent},
]
}];
Now i want the application to redirect to /terminvereinbarung/thema if page /terminvereinbarung is openend.
How can i achieve this?
Thanks a lot in adcance.
Keep all routing as it is just try adding this redirect in children in sub module
const appointmentAgreementRoutes: Routes = [{
path: '',
children: [
{ path: '', redirectTo: 'thema', pathMatch: 'full' },
{path: 'thema', component: TopicSectionComponent},
{path: 'filiale', component: BranchSectionComponent},
{path: 'termin', component: DatetimeSectionComponent},
{path: 'daten', component: PersonalDataSectionComponent},
{path: 'bestaetigung', component: ConfirmationSectionComponent},
]
}];
Try to do the following in appointmentAgreement component:
const appointmentAgreementRoutes: Routes = [{
{
path: 'terminvereinbarung',
redirectTo: 'thema',
pathMatch: 'full'
},
{
path: 'terminvereinbarung',
component: TopicSectionComponent,
}
children: [
{path: 'thema', component: TopicSectionComponent},
{path: 'filiale', component: BranchSectionComponent},
{path: 'termin', component: DatetimeSectionComponent},
{path: 'daten', component: PersonalDataSectionComponent},
{path: 'bestaetigung', component: ConfirmationSectionComponent},
]
}];

Can I use nested components linked with same app module? Is it good practise? Using component Router

Here is component structure of my application. Any advice will be valuable. Root component is app.
Which has two components as child : login & home.
home has two child components : dummy-component & dummy-component1.
Is it good practice? Will I face any issue if I switch component router to ui-router. I am also planning to switch from angular 1.6.0 to 2.0
App.component('app', {
templateUrl: 'core/app',
$routeConfig: [{
path: '/core/teamnest/login-component/',
name: 'LoginComponent',
component: 'loginComponent',
useAsDefault: true
},
{
path: '/core/teamnest/home-component/...',
name: 'HomeComponent',
component: 'homeComponent'
},
],
controller: appController
});
App.component('homeComponent', {
templateUrl: 'core/dashboard',
$routeConfig: [{
path: '/dummy-component',
name: 'DummyComponent',
component: 'dummyComponent',
useAsDefault: true
},
{
path: '/dummy-component1',
name: 'DummyComponent1',
component: 'dummyComponent1'
}
],
bindings: {
$router: '<'
},
controller: homeController
});
App.component('dummyComponent', {
templateUrl: 'core/dummy',
controller: dummyController
});
App.component('dummyComponent1', {
templateUrl: 'core/diff'
});

Angular Router nested named outlets

I'm using Angular (v2.4.5). Is it possible to have nested named outlets?
Here is my situation:
//app.component.html
<router-outlet name="test"></router-outlet>
<router-outlet></router-outlet>
//dashboard.component.html
<router-outlet name="test"></router-outlet>
<router-outlet></router-outlet>
Routes:
const routes: Routes = [
{
path: '',
redirectTo: '/dashboard',
pathMatch: 'full'
},
{
path: 'login',
component: LoginComponent
},
{
path: 'dashboard',
component: DashboardComponent,
canActivate: [AuthGuard],
children: [
{
path: '',
redirectTo: 'inbox',
pathMatch: 'full'
},
{
path: 'inbox',
component: InboxContentComponent
},
{
path: 'test',
component: TestComponent,
outlet: 'test'
}
],
{
path: 'test',
component: TestComponent,
outlet: 'test'
}
}
If I go to this url: http://localhost/login(test:test) the TestComponent is loaded in the app.component.html outlet.
If I go to this url: http://localhost/dashboard/inbox(test:test) the TestComponent is loaded in the app.component.html outlet and not in dashboard.component.html
I want to be able to target test outlet from dashboard. Is it possible?

Navigation Issue angular and typescript

I have an issue with my navigation bar. I used ngRoute from AngularJs and I can't understand why all the links work wrong at click.
Here my code:
app.ts file:
module AnimalPlanet {
export var app: angular.IModule;
app= angular.module("mainAnimalPlanet",["ngRoute"]);
app.config(['$routeProvider', ($routeProvider:ng.route.IRouteProvider, $locationProvider:angular.ILocationProvider) => {
$routeProvider.when('/', {
templateUrl: 'templates/main.html',
controller:"a"
})
.when('/pets', {
templateUrl: 'templates/pets.html',
controller:"MenuItemCtrl"
})
.when('/ldAdoption', {
templateUrl: 'templates/ldAdoption.html',
controller:"c"
})
.when('/111111', {
templateUrl: 'templates/contact.html',
controller:"d"
})
.when('/impressum', {
templateUrl: 'templates/impressum.html',
controller:"e"
})
.otherwise({
redirectTo: '/'
});
}]);
}
menuItem.ts file:
"use strict";
module AnimalPlanet {
export class MenuItemCtrl {
names: any[];
constructor(names) {
this.names = [{
name: "Main",
slug: "main",
active: true,
link: "/"
}, {
name: "Pets",
slug: "pets",
active: false,
link: "/pets"
}, {
name: "LDAdoption",
slug: "ldAdoption",
active: false,
link: "/ldAdoption"
}, {
name: "Contact",
slug: "contact",
active: false,
link: "/contact"
}, {
name: "Impressum",
slug: "impressum",
active: false,
link: "/impressum"
}];
}
}
angular.module('mainAnimalPlanet',['ngRoute']).controller("MenuItemCtrl", ["$scope", MenuItemCtrl]);
}
Please help me!!! Thank you!

Resources