Routing angular in the same route if the user is logged or not2019 Community Moderator ElectionAngular 2 Routing- Cannot find primary outlet to load 'AppComponent'Angular2 Routing with base selector as Component in index.htmlAngular routing canActivate AuthGuard transmit query paramsAngular 5 EmptyError: no elements in sequence while making child routesAngular 5 canActivate not workingAngular routing to always go to login page if user is not logged inAngular Login Component Redirect if User is Already loggedCan't stop home redirect routing for already logged userAngular Router Ordering?Angular - 404 when navigating to other component

Giving a talk in my old university, how prominently should I tell students my salary?

How do you make a gun that shoots melee weapons and/or swords?

3.5% Interest Student Loan or use all of my savings on Tuition?

Vector-transposing function

PTIJ: Sport in the Torah

How does a sound wave propagate?

Why isn't P and P/poly trivially the same?

How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?

Is there a logarithm base for which the logarithm becomes an identity function?

Is it a Cyclops number? "Nobody" knows!

How would an energy-based "projectile" blow up a spaceship?

How to recover against Snake as a heavyweight character?

Was it really inappropriate to write a pull request for the company I interviewed with?

Can I negotiate a patent idea for a raise, under French law?

Do I need a return ticket to Canada if I'm a Japanese National?

Where is the License file location for Identity Server in Sitecore 9.1?

How to educate team mate to take screenshots for bugs with out unwanted stuff

Should I apply for my boss's promotion?

What is the purpose of a disclaimer like "this is not legal advice"?

Boss Telling direct supervisor I snitched

Why do we call complex numbers “numbers” but we don’t consider 2-vectors numbers?

Is this Paypal Github SDK reference really a dangerous site?

Will the concrete slab in a partially heated shed conduct a lot of heat to the unconditioned area?

Inorganic chemistry handbook with reaction lists



Routing angular in the same route if the user is logged or not



2019 Community Moderator ElectionAngular 2 Routing- Cannot find primary outlet to load 'AppComponent'Angular2 Routing with base selector as Component in index.htmlAngular routing canActivate AuthGuard transmit query paramsAngular 5 EmptyError: no elements in sequence while making child routesAngular 5 canActivate not workingAngular routing to always go to login page if user is not logged inAngular Login Component Redirect if User is Already loggedCan't stop home redirect routing for already logged userAngular Router Ordering?Angular - 404 when navigating to other component










0















so far, for differenciate the pages I had to play around whit the children route, basically if the user is logged the MainComponent has to be loaded because in that there is the top bar.
Instead when the user goes to login the top bar is not loaded.



I'd like that when the user is logged and he goes to the page loaded would be the dashboard and instead when he is not and he goes to the page loaded would be the login page.



I tried to use the authguard but every time that I'm adding canActivate: [AuthGuard] my site doesn't work anymore.



my file app-routing.module.ts is :



const routes: Routes = [

path: '',
component: MainComponent,
children: [
path: '', component: DashboardComponent ,
path: 'missions', component: MissionComponent ,
path: 'operators', component: OperatorComponent ,
path: 'materials', component: MaterialComponent ,
path: 'bins', component: BinComponent ,
path: 'main', component: MainComponent ,
]
,
path: 'login', component: LoginComponent ,

];


my auth.guard.ts is :



constructor(
public afAuth: AngularFireAuth,
public userService: UserService,
private router: Router
)

canActivate(): Promise<boolean>
return new Promise((resolve, reject) =>
this.userService.getCurrentUser()
.then(user =>
//this.router.navigate(['/operator']);
return resolve(false);
, err =>
return resolve(true);
);
);










share|improve this question






















  • What error do you get? Why the site not working?

    – Maihan Nijat
    2 days ago











  • I don't get any error, simply everithing is blank

    – alessandro buffoli
    2 days ago











  • Check with chrome. The console.

    – Maihan Nijat
    2 days ago






  • 1





    You can use enableTracing to get which route is getting loaded with route guard angular.io/api/router/ExtraOptions#enableTracing . It should help to understand whats going on.

    – Nikhil Walvekar
    2 days ago











  • @MaihanNijat already checked, the console is clear..

    – alessandro buffoli
    2 days ago















0















so far, for differenciate the pages I had to play around whit the children route, basically if the user is logged the MainComponent has to be loaded because in that there is the top bar.
Instead when the user goes to login the top bar is not loaded.



I'd like that when the user is logged and he goes to the page loaded would be the dashboard and instead when he is not and he goes to the page loaded would be the login page.



I tried to use the authguard but every time that I'm adding canActivate: [AuthGuard] my site doesn't work anymore.



my file app-routing.module.ts is :



const routes: Routes = [

path: '',
component: MainComponent,
children: [
path: '', component: DashboardComponent ,
path: 'missions', component: MissionComponent ,
path: 'operators', component: OperatorComponent ,
path: 'materials', component: MaterialComponent ,
path: 'bins', component: BinComponent ,
path: 'main', component: MainComponent ,
]
,
path: 'login', component: LoginComponent ,

];


my auth.guard.ts is :



constructor(
public afAuth: AngularFireAuth,
public userService: UserService,
private router: Router
)

canActivate(): Promise<boolean>
return new Promise((resolve, reject) =>
this.userService.getCurrentUser()
.then(user =>
//this.router.navigate(['/operator']);
return resolve(false);
, err =>
return resolve(true);
);
);










share|improve this question






















  • What error do you get? Why the site not working?

    – Maihan Nijat
    2 days ago











  • I don't get any error, simply everithing is blank

    – alessandro buffoli
    2 days ago











  • Check with chrome. The console.

    – Maihan Nijat
    2 days ago






  • 1





    You can use enableTracing to get which route is getting loaded with route guard angular.io/api/router/ExtraOptions#enableTracing . It should help to understand whats going on.

    – Nikhil Walvekar
    2 days ago











  • @MaihanNijat already checked, the console is clear..

    – alessandro buffoli
    2 days ago













0












0








0








so far, for differenciate the pages I had to play around whit the children route, basically if the user is logged the MainComponent has to be loaded because in that there is the top bar.
Instead when the user goes to login the top bar is not loaded.



I'd like that when the user is logged and he goes to the page loaded would be the dashboard and instead when he is not and he goes to the page loaded would be the login page.



I tried to use the authguard but every time that I'm adding canActivate: [AuthGuard] my site doesn't work anymore.



my file app-routing.module.ts is :



const routes: Routes = [

path: '',
component: MainComponent,
children: [
path: '', component: DashboardComponent ,
path: 'missions', component: MissionComponent ,
path: 'operators', component: OperatorComponent ,
path: 'materials', component: MaterialComponent ,
path: 'bins', component: BinComponent ,
path: 'main', component: MainComponent ,
]
,
path: 'login', component: LoginComponent ,

];


my auth.guard.ts is :



constructor(
public afAuth: AngularFireAuth,
public userService: UserService,
private router: Router
)

canActivate(): Promise<boolean>
return new Promise((resolve, reject) =>
this.userService.getCurrentUser()
.then(user =>
//this.router.navigate(['/operator']);
return resolve(false);
, err =>
return resolve(true);
);
);










share|improve this question














so far, for differenciate the pages I had to play around whit the children route, basically if the user is logged the MainComponent has to be loaded because in that there is the top bar.
Instead when the user goes to login the top bar is not loaded.



I'd like that when the user is logged and he goes to the page loaded would be the dashboard and instead when he is not and he goes to the page loaded would be the login page.



I tried to use the authguard but every time that I'm adding canActivate: [AuthGuard] my site doesn't work anymore.



my file app-routing.module.ts is :



const routes: Routes = [

path: '',
component: MainComponent,
children: [
path: '', component: DashboardComponent ,
path: 'missions', component: MissionComponent ,
path: 'operators', component: OperatorComponent ,
path: 'materials', component: MaterialComponent ,
path: 'bins', component: BinComponent ,
path: 'main', component: MainComponent ,
]
,
path: 'login', component: LoginComponent ,

];


my auth.guard.ts is :



constructor(
public afAuth: AngularFireAuth,
public userService: UserService,
private router: Router
)

canActivate(): Promise<boolean>
return new Promise((resolve, reject) =>
this.userService.getCurrentUser()
.then(user =>
//this.router.navigate(['/operator']);
return resolve(false);
, err =>
return resolve(true);
);
);







angular routing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









alessandro buffolialessandro buffoli

758




758












  • What error do you get? Why the site not working?

    – Maihan Nijat
    2 days ago











  • I don't get any error, simply everithing is blank

    – alessandro buffoli
    2 days ago











  • Check with chrome. The console.

    – Maihan Nijat
    2 days ago






  • 1





    You can use enableTracing to get which route is getting loaded with route guard angular.io/api/router/ExtraOptions#enableTracing . It should help to understand whats going on.

    – Nikhil Walvekar
    2 days ago











  • @MaihanNijat already checked, the console is clear..

    – alessandro buffoli
    2 days ago

















  • What error do you get? Why the site not working?

    – Maihan Nijat
    2 days ago











  • I don't get any error, simply everithing is blank

    – alessandro buffoli
    2 days ago











  • Check with chrome. The console.

    – Maihan Nijat
    2 days ago






  • 1





    You can use enableTracing to get which route is getting loaded with route guard angular.io/api/router/ExtraOptions#enableTracing . It should help to understand whats going on.

    – Nikhil Walvekar
    2 days ago











  • @MaihanNijat already checked, the console is clear..

    – alessandro buffoli
    2 days ago
















What error do you get? Why the site not working?

– Maihan Nijat
2 days ago





What error do you get? Why the site not working?

– Maihan Nijat
2 days ago













I don't get any error, simply everithing is blank

– alessandro buffoli
2 days ago





I don't get any error, simply everithing is blank

– alessandro buffoli
2 days ago













Check with chrome. The console.

– Maihan Nijat
2 days ago





Check with chrome. The console.

– Maihan Nijat
2 days ago




1




1





You can use enableTracing to get which route is getting loaded with route guard angular.io/api/router/ExtraOptions#enableTracing . It should help to understand whats going on.

– Nikhil Walvekar
2 days ago





You can use enableTracing to get which route is getting loaded with route guard angular.io/api/router/ExtraOptions#enableTracing . It should help to understand whats going on.

– Nikhil Walvekar
2 days ago













@MaihanNijat already checked, the console is clear..

– alessandro buffoli
2 days ago





@MaihanNijat already checked, the console is clear..

– alessandro buffoli
2 days ago












1 Answer
1






active

oldest

votes


















1














Try this:



canActivate() 
return this.userService.getCurrentUser()
.pipe(
tap(user =>
if (!user)
this.router.navigate(['/operator']);

),
);



If the user is returned, it means it is logged in and if not then it will be redirected where ever you want to redirect.






share|improve this answer























  • Thankyou for your reply, this helped a lot! It was not the solution but I could debug from console.log!

    – alessandro buffoli
    yesterday






  • 1





    @alessandrobuffoli I am glad you solved your problem.

    – Maihan Nijat
    yesterday










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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55028076%2frouting-angular-in-the-same-route-if-the-user-is-logged-or-not%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









1














Try this:



canActivate() 
return this.userService.getCurrentUser()
.pipe(
tap(user =>
if (!user)
this.router.navigate(['/operator']);

),
);



If the user is returned, it means it is logged in and if not then it will be redirected where ever you want to redirect.






share|improve this answer























  • Thankyou for your reply, this helped a lot! It was not the solution but I could debug from console.log!

    – alessandro buffoli
    yesterday






  • 1





    @alessandrobuffoli I am glad you solved your problem.

    – Maihan Nijat
    yesterday















1














Try this:



canActivate() 
return this.userService.getCurrentUser()
.pipe(
tap(user =>
if (!user)
this.router.navigate(['/operator']);

),
);



If the user is returned, it means it is logged in and if not then it will be redirected where ever you want to redirect.






share|improve this answer























  • Thankyou for your reply, this helped a lot! It was not the solution but I could debug from console.log!

    – alessandro buffoli
    yesterday






  • 1





    @alessandrobuffoli I am glad you solved your problem.

    – Maihan Nijat
    yesterday













1












1








1







Try this:



canActivate() 
return this.userService.getCurrentUser()
.pipe(
tap(user =>
if (!user)
this.router.navigate(['/operator']);

),
);



If the user is returned, it means it is logged in and if not then it will be redirected where ever you want to redirect.






share|improve this answer













Try this:



canActivate() 
return this.userService.getCurrentUser()
.pipe(
tap(user =>
if (!user)
this.router.navigate(['/operator']);

),
);



If the user is returned, it means it is logged in and if not then it will be redirected where ever you want to redirect.







share|improve this answer












share|improve this answer



share|improve this answer










answered 2 days ago









Maihan NijatMaihan Nijat

2,84722347




2,84722347












  • Thankyou for your reply, this helped a lot! It was not the solution but I could debug from console.log!

    – alessandro buffoli
    yesterday






  • 1





    @alessandrobuffoli I am glad you solved your problem.

    – Maihan Nijat
    yesterday

















  • Thankyou for your reply, this helped a lot! It was not the solution but I could debug from console.log!

    – alessandro buffoli
    yesterday






  • 1





    @alessandrobuffoli I am glad you solved your problem.

    – Maihan Nijat
    yesterday
















Thankyou for your reply, this helped a lot! It was not the solution but I could debug from console.log!

– alessandro buffoli
yesterday





Thankyou for your reply, this helped a lot! It was not the solution but I could debug from console.log!

– alessandro buffoli
yesterday




1




1





@alessandrobuffoli I am glad you solved your problem.

– Maihan Nijat
yesterday





@alessandrobuffoli I am glad you solved your problem.

– Maihan Nijat
yesterday



















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55028076%2frouting-angular-in-the-same-route-if-the-user-is-logged-or-not%23new-answer', 'question_page');

);

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







Popular posts from this blog

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

Can't find variable: document ReactNative Js2019 Community Moderator ElectionReactNative: how to center text?Can't find variable: navigate - ReactNative navigationReact Native error: “Can't find variable: TouchableHighlight”How to use Expo.DocumentPicker.getDocumentAsync properly. [Expo] [ReactNative]Can't find variable: regeneratorRuntime (ReactNative)Reactnative Expo It is advisable for a StartUp?Can't find variable : Self / Can't install firebaseNPM Install Error in installing ReactNative CLIContacts Displaying in App using ReactnativeFacebook login error: can't find variable: Alert

Posting a File and Associated Data to a RESTful WebService preferably as JSON2019 Community Moderator ElectionREST URI convention - Singular or plural name of resource while creating itUploading both data and files in one form using Ajax?How do I upload a file with metadata using a REST web service?REST API - file (ie images) processing - best practicesSpring: JSON data and file in the same requestREST API Put large dataPosting a file and JSON data to Spring rest serviceRESTful Web Service Upload/Download Large Data With JSONREST API Design sending JSON data and a file to the api in same requestPost JSONArray to REST servicePUT vs. POST in RESTParsing values from a JSON file?JavaScript/jQuery to download file via POST with JSON dataHow do I upload a file with metadata using a REST web service?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Separate REST JSON API server and client?what's the correct way to send a file from REST web service to client?How do I write JSON data to a file?What is “406-Not Acceptable Response” in HTTP?REST API - file (ie images) processing - best practices