Why do I get the sign “?” at the start of the URL and reboot the app when navigating the absolute path?
I have problem.
I have a multi-module application with lazy loading.
When I navigate from top module to bottom child module, everything is fine.
But when I try to route from a bottom child lazy module to another child lazy module, I get strange behavior.
It's ok :
=> http://localhost:4200/#/op/services/ =>
=> http://localhost:4200/#/op/services/management/ =>
=> http://localhost:4200/#/op/services/management/edit/123
=> http://localhost:4200/#/op
=> http://localhost:4200/#/op/test/management/
=> http://localhost:4200/#/op/test/management/edit/321
This is bad:
http://localhost:4200/#/op/test/management/edit/321 =>
=> http://localhost:4200/#/op/services/management/edit/123
When I try it, I got '?' sign in start URL, like
http://localhost:4200/?#/op/services/management/edit/123
and my app was full reload!
It doesn't matter if a lazy module is loaded or not, as I found out, this does not affect the problem.
This problem is repeated unstable, sometimes the transition works as expected!
I tried many combinations, but the problem can not solve.
That I tried:
this.router.navigate([op/services/management/edit/${id}]);
this.router.navigate([/op/services/management/edit/${id}]);
this.router.navigate(['/op/services/management/edit/', id]);
this.router.navigateByUrl(op/services/management/edit/${id});
this.router.navigateByUrl(/op/services/management/edit/${id});
routerLink = "/op/services/management/edit/123"
routerLink = "op/services/management/edit/123"
Help me understand why the route changes?
UPDATE.
Add smiplify route config:
Basic module:
const routes: Routes = [
{
path: '', loadChildren: './path/to/op.module#OperatorModule',
data: {
preload: false,
base: true,
},
},
...
];
@NgModule({
imports: [RouterModule.forRoot(
routes,
{
useHash: true,
preloadingStrategy: SelectivePreloadingStrategy,
},
)],
exports: [RouterModule],
})
export class AppRoutingModule {}
Operator module which contains my inner lazy modules:
const routes: Routes = [
{
path: 'op',
component: BasePage,
canActivate: [AuthGuard],
children: [
{
path: 'services/management',
loadChildren: './services/services.module#ServicesModule',
canActivate: [AuthGuard],
data: {
preload: true,
},
},
{
path: 'tests/management',
loadChildren: './tests/tests.module#TestsModule',
canActivate: [AuthGuard],
data: {
preload: true,
},
},
...
],
},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class OperatorRoutingModule {
}
Router modules for some of inner module:
For services:
const routes: Routes = [
{
path: '',
data: {
...
},
pathMatch: 'full',
component: ServicesPage,
canActivate: [AuthGuard],
},
{
path: 'edit/:id',
data: {
accessRole: [UserRole.USER, UserRole.ADMIN],
},
component: ServicePage,
canDeactivate: [CanDeactivateGuard],
canActivate: [AuthGuard, RoleGuard],
},
....
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class ServicesRoutingModule {
}
For tests:
const routes: Routes = [
{
path: '',
data: {
...
},
pathMatch: 'full',
component: TestsPage,
canActivate: [AuthGuard],
},
{
path: 'edit/:id',
data: {
accessRole: [UserRole.USER, UserRole.ADMIN],
},
component: TestPage,
canDeactivate: [CanDeactivateGuard],
canActivate: [AuthGuard, RoleGuard],
},
....
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class TestsRoutingModule {
}
UPDATE!
I found a new reason.
The problem happens if I try to make the routing in HTML form.
I have a CanDeactivate service warning about leaving the page.
I noticed that the window:befeoreonload
works on any form, even if disabled CanDeactivate service on this page.
I have not yet understood, how it can be dependent, but I think, I'm on the right way.
angular typescript
|
show 1 more comment
I have problem.
I have a multi-module application with lazy loading.
When I navigate from top module to bottom child module, everything is fine.
But when I try to route from a bottom child lazy module to another child lazy module, I get strange behavior.
It's ok :
=> http://localhost:4200/#/op/services/ =>
=> http://localhost:4200/#/op/services/management/ =>
=> http://localhost:4200/#/op/services/management/edit/123
=> http://localhost:4200/#/op
=> http://localhost:4200/#/op/test/management/
=> http://localhost:4200/#/op/test/management/edit/321
This is bad:
http://localhost:4200/#/op/test/management/edit/321 =>
=> http://localhost:4200/#/op/services/management/edit/123
When I try it, I got '?' sign in start URL, like
http://localhost:4200/?#/op/services/management/edit/123
and my app was full reload!
It doesn't matter if a lazy module is loaded or not, as I found out, this does not affect the problem.
This problem is repeated unstable, sometimes the transition works as expected!
I tried many combinations, but the problem can not solve.
That I tried:
this.router.navigate([op/services/management/edit/${id}]);
this.router.navigate([/op/services/management/edit/${id}]);
this.router.navigate(['/op/services/management/edit/', id]);
this.router.navigateByUrl(op/services/management/edit/${id});
this.router.navigateByUrl(/op/services/management/edit/${id});
routerLink = "/op/services/management/edit/123"
routerLink = "op/services/management/edit/123"
Help me understand why the route changes?
UPDATE.
Add smiplify route config:
Basic module:
const routes: Routes = [
{
path: '', loadChildren: './path/to/op.module#OperatorModule',
data: {
preload: false,
base: true,
},
},
...
];
@NgModule({
imports: [RouterModule.forRoot(
routes,
{
useHash: true,
preloadingStrategy: SelectivePreloadingStrategy,
},
)],
exports: [RouterModule],
})
export class AppRoutingModule {}
Operator module which contains my inner lazy modules:
const routes: Routes = [
{
path: 'op',
component: BasePage,
canActivate: [AuthGuard],
children: [
{
path: 'services/management',
loadChildren: './services/services.module#ServicesModule',
canActivate: [AuthGuard],
data: {
preload: true,
},
},
{
path: 'tests/management',
loadChildren: './tests/tests.module#TestsModule',
canActivate: [AuthGuard],
data: {
preload: true,
},
},
...
],
},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class OperatorRoutingModule {
}
Router modules for some of inner module:
For services:
const routes: Routes = [
{
path: '',
data: {
...
},
pathMatch: 'full',
component: ServicesPage,
canActivate: [AuthGuard],
},
{
path: 'edit/:id',
data: {
accessRole: [UserRole.USER, UserRole.ADMIN],
},
component: ServicePage,
canDeactivate: [CanDeactivateGuard],
canActivate: [AuthGuard, RoleGuard],
},
....
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class ServicesRoutingModule {
}
For tests:
const routes: Routes = [
{
path: '',
data: {
...
},
pathMatch: 'full',
component: TestsPage,
canActivate: [AuthGuard],
},
{
path: 'edit/:id',
data: {
accessRole: [UserRole.USER, UserRole.ADMIN],
},
component: TestPage,
canDeactivate: [CanDeactivateGuard],
canActivate: [AuthGuard, RoleGuard],
},
....
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class TestsRoutingModule {
}
UPDATE!
I found a new reason.
The problem happens if I try to make the routing in HTML form.
I have a CanDeactivate service warning about leaving the page.
I noticed that the window:befeoreonload
works on any form, even if disabled CanDeactivate service on this page.
I have not yet understood, how it can be dependent, but I think, I'm on the right way.
angular typescript
Try like this. this._router.navigate(['/op/services/management/edit/', id]);
– Suresh Kumar Ariya
Nov 12 '18 at 7:50
What is '_router' ? I also try something like this: this.router.navigate(['/op/services/management/edit/', id]);
– BratchVV
Nov 12 '18 at 8:05
Share your routing configuration.
– Sunil Singh
Nov 12 '18 at 8:10
The issue is, way of Forming the router URL has issues.
– Suresh Kumar Ariya
Nov 12 '18 at 8:22
see my updates, please
– BratchVV
Nov 12 '18 at 8:43
|
show 1 more comment
I have problem.
I have a multi-module application with lazy loading.
When I navigate from top module to bottom child module, everything is fine.
But when I try to route from a bottom child lazy module to another child lazy module, I get strange behavior.
It's ok :
=> http://localhost:4200/#/op/services/ =>
=> http://localhost:4200/#/op/services/management/ =>
=> http://localhost:4200/#/op/services/management/edit/123
=> http://localhost:4200/#/op
=> http://localhost:4200/#/op/test/management/
=> http://localhost:4200/#/op/test/management/edit/321
This is bad:
http://localhost:4200/#/op/test/management/edit/321 =>
=> http://localhost:4200/#/op/services/management/edit/123
When I try it, I got '?' sign in start URL, like
http://localhost:4200/?#/op/services/management/edit/123
and my app was full reload!
It doesn't matter if a lazy module is loaded or not, as I found out, this does not affect the problem.
This problem is repeated unstable, sometimes the transition works as expected!
I tried many combinations, but the problem can not solve.
That I tried:
this.router.navigate([op/services/management/edit/${id}]);
this.router.navigate([/op/services/management/edit/${id}]);
this.router.navigate(['/op/services/management/edit/', id]);
this.router.navigateByUrl(op/services/management/edit/${id});
this.router.navigateByUrl(/op/services/management/edit/${id});
routerLink = "/op/services/management/edit/123"
routerLink = "op/services/management/edit/123"
Help me understand why the route changes?
UPDATE.
Add smiplify route config:
Basic module:
const routes: Routes = [
{
path: '', loadChildren: './path/to/op.module#OperatorModule',
data: {
preload: false,
base: true,
},
},
...
];
@NgModule({
imports: [RouterModule.forRoot(
routes,
{
useHash: true,
preloadingStrategy: SelectivePreloadingStrategy,
},
)],
exports: [RouterModule],
})
export class AppRoutingModule {}
Operator module which contains my inner lazy modules:
const routes: Routes = [
{
path: 'op',
component: BasePage,
canActivate: [AuthGuard],
children: [
{
path: 'services/management',
loadChildren: './services/services.module#ServicesModule',
canActivate: [AuthGuard],
data: {
preload: true,
},
},
{
path: 'tests/management',
loadChildren: './tests/tests.module#TestsModule',
canActivate: [AuthGuard],
data: {
preload: true,
},
},
...
],
},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class OperatorRoutingModule {
}
Router modules for some of inner module:
For services:
const routes: Routes = [
{
path: '',
data: {
...
},
pathMatch: 'full',
component: ServicesPage,
canActivate: [AuthGuard],
},
{
path: 'edit/:id',
data: {
accessRole: [UserRole.USER, UserRole.ADMIN],
},
component: ServicePage,
canDeactivate: [CanDeactivateGuard],
canActivate: [AuthGuard, RoleGuard],
},
....
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class ServicesRoutingModule {
}
For tests:
const routes: Routes = [
{
path: '',
data: {
...
},
pathMatch: 'full',
component: TestsPage,
canActivate: [AuthGuard],
},
{
path: 'edit/:id',
data: {
accessRole: [UserRole.USER, UserRole.ADMIN],
},
component: TestPage,
canDeactivate: [CanDeactivateGuard],
canActivate: [AuthGuard, RoleGuard],
},
....
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class TestsRoutingModule {
}
UPDATE!
I found a new reason.
The problem happens if I try to make the routing in HTML form.
I have a CanDeactivate service warning about leaving the page.
I noticed that the window:befeoreonload
works on any form, even if disabled CanDeactivate service on this page.
I have not yet understood, how it can be dependent, but I think, I'm on the right way.
angular typescript
I have problem.
I have a multi-module application with lazy loading.
When I navigate from top module to bottom child module, everything is fine.
But when I try to route from a bottom child lazy module to another child lazy module, I get strange behavior.
It's ok :
=> http://localhost:4200/#/op/services/ =>
=> http://localhost:4200/#/op/services/management/ =>
=> http://localhost:4200/#/op/services/management/edit/123
=> http://localhost:4200/#/op
=> http://localhost:4200/#/op/test/management/
=> http://localhost:4200/#/op/test/management/edit/321
This is bad:
http://localhost:4200/#/op/test/management/edit/321 =>
=> http://localhost:4200/#/op/services/management/edit/123
When I try it, I got '?' sign in start URL, like
http://localhost:4200/?#/op/services/management/edit/123
and my app was full reload!
It doesn't matter if a lazy module is loaded or not, as I found out, this does not affect the problem.
This problem is repeated unstable, sometimes the transition works as expected!
I tried many combinations, but the problem can not solve.
That I tried:
this.router.navigate([op/services/management/edit/${id}]);
this.router.navigate([/op/services/management/edit/${id}]);
this.router.navigate(['/op/services/management/edit/', id]);
this.router.navigateByUrl(op/services/management/edit/${id});
this.router.navigateByUrl(/op/services/management/edit/${id});
routerLink = "/op/services/management/edit/123"
routerLink = "op/services/management/edit/123"
Help me understand why the route changes?
UPDATE.
Add smiplify route config:
Basic module:
const routes: Routes = [
{
path: '', loadChildren: './path/to/op.module#OperatorModule',
data: {
preload: false,
base: true,
},
},
...
];
@NgModule({
imports: [RouterModule.forRoot(
routes,
{
useHash: true,
preloadingStrategy: SelectivePreloadingStrategy,
},
)],
exports: [RouterModule],
})
export class AppRoutingModule {}
Operator module which contains my inner lazy modules:
const routes: Routes = [
{
path: 'op',
component: BasePage,
canActivate: [AuthGuard],
children: [
{
path: 'services/management',
loadChildren: './services/services.module#ServicesModule',
canActivate: [AuthGuard],
data: {
preload: true,
},
},
{
path: 'tests/management',
loadChildren: './tests/tests.module#TestsModule',
canActivate: [AuthGuard],
data: {
preload: true,
},
},
...
],
},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class OperatorRoutingModule {
}
Router modules for some of inner module:
For services:
const routes: Routes = [
{
path: '',
data: {
...
},
pathMatch: 'full',
component: ServicesPage,
canActivate: [AuthGuard],
},
{
path: 'edit/:id',
data: {
accessRole: [UserRole.USER, UserRole.ADMIN],
},
component: ServicePage,
canDeactivate: [CanDeactivateGuard],
canActivate: [AuthGuard, RoleGuard],
},
....
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class ServicesRoutingModule {
}
For tests:
const routes: Routes = [
{
path: '',
data: {
...
},
pathMatch: 'full',
component: TestsPage,
canActivate: [AuthGuard],
},
{
path: 'edit/:id',
data: {
accessRole: [UserRole.USER, UserRole.ADMIN],
},
component: TestPage,
canDeactivate: [CanDeactivateGuard],
canActivate: [AuthGuard, RoleGuard],
},
....
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class TestsRoutingModule {
}
UPDATE!
I found a new reason.
The problem happens if I try to make the routing in HTML form.
I have a CanDeactivate service warning about leaving the page.
I noticed that the window:befeoreonload
works on any form, even if disabled CanDeactivate service on this page.
I have not yet understood, how it can be dependent, but I think, I'm on the right way.
angular typescript
angular typescript
edited Nov 12 '18 at 12:15
asked Nov 12 '18 at 7:28
BratchVV
104
104
Try like this. this._router.navigate(['/op/services/management/edit/', id]);
– Suresh Kumar Ariya
Nov 12 '18 at 7:50
What is '_router' ? I also try something like this: this.router.navigate(['/op/services/management/edit/', id]);
– BratchVV
Nov 12 '18 at 8:05
Share your routing configuration.
– Sunil Singh
Nov 12 '18 at 8:10
The issue is, way of Forming the router URL has issues.
– Suresh Kumar Ariya
Nov 12 '18 at 8:22
see my updates, please
– BratchVV
Nov 12 '18 at 8:43
|
show 1 more comment
Try like this. this._router.navigate(['/op/services/management/edit/', id]);
– Suresh Kumar Ariya
Nov 12 '18 at 7:50
What is '_router' ? I also try something like this: this.router.navigate(['/op/services/management/edit/', id]);
– BratchVV
Nov 12 '18 at 8:05
Share your routing configuration.
– Sunil Singh
Nov 12 '18 at 8:10
The issue is, way of Forming the router URL has issues.
– Suresh Kumar Ariya
Nov 12 '18 at 8:22
see my updates, please
– BratchVV
Nov 12 '18 at 8:43
Try like this. this._router.navigate(['/op/services/management/edit/', id]);
– Suresh Kumar Ariya
Nov 12 '18 at 7:50
Try like this. this._router.navigate(['/op/services/management/edit/', id]);
– Suresh Kumar Ariya
Nov 12 '18 at 7:50
What is '_router' ? I also try something like this: this.router.navigate(['/op/services/management/edit/', id]);
– BratchVV
Nov 12 '18 at 8:05
What is '_router' ? I also try something like this: this.router.navigate(['/op/services/management/edit/', id]);
– BratchVV
Nov 12 '18 at 8:05
Share your routing configuration.
– Sunil Singh
Nov 12 '18 at 8:10
Share your routing configuration.
– Sunil Singh
Nov 12 '18 at 8:10
The issue is, way of Forming the router URL has issues.
– Suresh Kumar Ariya
Nov 12 '18 at 8:22
The issue is, way of Forming the router URL has issues.
– Suresh Kumar Ariya
Nov 12 '18 at 8:22
see my updates, please
– BratchVV
Nov 12 '18 at 8:43
see my updates, please
– BratchVV
Nov 12 '18 at 8:43
|
show 1 more comment
1 Answer
1
active
oldest
votes
The route button had a default type, that is, 'submit', and its button was in form...
Change it to type='button' and all work fine!
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257555%2fwhy-do-i-get-the-sign-at-the-start-of-the-url-and-reboot-the-app-when-naviga%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The route button had a default type, that is, 'submit', and its button was in form...
Change it to type='button' and all work fine!
add a comment |
The route button had a default type, that is, 'submit', and its button was in form...
Change it to type='button' and all work fine!
add a comment |
The route button had a default type, that is, 'submit', and its button was in form...
Change it to type='button' and all work fine!
The route button had a default type, that is, 'submit', and its button was in form...
Change it to type='button' and all work fine!
answered Nov 12 '18 at 12:35
BratchVV
104
104
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257555%2fwhy-do-i-get-the-sign-at-the-start-of-the-url-and-reboot-the-app-when-naviga%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try like this. this._router.navigate(['/op/services/management/edit/', id]);
– Suresh Kumar Ariya
Nov 12 '18 at 7:50
What is '_router' ? I also try something like this: this.router.navigate(['/op/services/management/edit/', id]);
– BratchVV
Nov 12 '18 at 8:05
Share your routing configuration.
– Sunil Singh
Nov 12 '18 at 8:10
The issue is, way of Forming the router URL has issues.
– Suresh Kumar Ariya
Nov 12 '18 at 8:22
see my updates, please
– BratchVV
Nov 12 '18 at 8:43