Reputation: 1524
First my URL IS:
/pages/check_info/add_info
after clicking the button in that pages it loads URL:
/pages/check_info/add_visitor.
the problem is that after the form has been loaded of add_visitor
the URL changes back to
/pages/check_info/add_info
but the add_visitor
page is still there.
Now when I click a button that links back to add_info
the button does not redirect anywhere as the current URL is the same
The code i have used for the button is
<div class="btn-area">
<button md-raised-button class="btn btn-primary btn-rounded"
type="submit">PLEASE CHECK IN</button>
<a routerLink='/pages/check-info/add_info'>BACK</a>
</div>
The code i have used for routing:
const routes: Routes = [
{path: '',redirectTo: 'add_info', pathMatch: 'full'},
{path: 'add_info', component: AddInfoComponent},
{path: 'display_info', component: DisplayInfoComponent},
{path: 'add_visitor', component: AddVisitorComponent},
{path: 'search_student', component: SearchStudentComponent},
{path: 'add_student', component: AddStudentComponent},
{path: 'add_graduate', component: AddGraduateComponent},
{path: 'check-in', component: AddInfoComponent},
];
Upvotes: 2
Views: 798
Reputation: 1524
The problem was not with the route or the patch of code from the view. In angular if there are errors with services, packages or anything in the TS, When the path is being redirected to a page with some of these errors the page loads but the url changes back to the previous URL.
Upvotes: 0
Reputation: 3778
try to change your link as follow:
<div class="btn-area">
<button md-raised-button class="btn btn-primary btn-rounded"
type="submit">PLEASE CHECK IN</button>
<a routerLink="['/pages/check-info/add_info']">BACK</a>
</div>
So change it with
routerLink="['/pages/check-info/add_info']"
Hope it helps you!
P.S it always redirect to add_info CAUSE it is the DEFAULT ROUTING ... so if it doesn't match any existing route it always redirect to it ...
If you want a routing like yours /pages/check-info/add_info you have to do a routing with child:
so for example:
{path: 'pages', component: PageComponent,
child[
{ path: 'check-info', component: CheckInfoComponent}
]},
and so on
Upvotes: 1