i am working on an app with Meteor that requires social shares. So I want to implement a social share on the single-post page.
I so I have this registered helper for facebook share:
Template.registerHelper('shareOnFacebookLink', function() {
return 'https://www.facebook.com/sharer/sharer.php?&u=' + window.location.href;
});
and in the template, I have this :
<a href="{{shareOnFacebookLink}}" target="_blank" class="btn btn-facebook">
<i class="fa fa-facebook"></i>
</a>
The problem is that when i navigate from the homepage to the single-post (where the registered helper is needed), the window.location.href still shows the href of the previous page until I reload the the single-post page.
What i want is how can I make the window.location.href get the href of the single-question page as soon as I land on it without having to refresh it?
Thanks all
You can try to use Meteor.Router.path() to get your current path.
Related
I wanted to ask if it is possible to pass data to my methods via router link in vue. I am a beginner who made a .net core api with the help of a youtube video and then call it in a html with vue/javascript. Now I have different components and each one is a separate js file which I don't find very nice because actually in all of them the same thing happens.
For example (html router link):
<li class="nav-item m-2">
<router-link class="btn btn-light btn-outline-primary" to="/home">GM10</router-link>
</li>
goes to home compnent which calls the api here and stores the json in chashier:
data(){
return{
chasier:[],
}
},
methods:{
refreshData(){
axios.get(variables.API_URL+'Store10')
.then((response)=>{
this.chasier=response.data
})
}
},
Second router link would be
<router-link class="btn btn-light btn-outline-primary" to="/GM11">GM11</router-link>
which goes to component gm11 but home and gm11 are the same except in gm11 it says axios.get(variables.API_URL+'Store11')
I would like to use only one js so that the router link "to" is the same for both but depending on which router link you press the url ending changes.
I tried already some stuff from the web but I nothing is really working. I lack of understanding and only the Youtube Video was not enough
Hi i have used anchor tag for opening the routerLink in new tab. Now if i click on logout, the routerLink in the new tab remains same, if there is any API hit then the routerLink redrirects to login page. But i want all the tabs to close as soon i logout, as the other router pages doesnt have header in the screen.
Header.component.ts:
public logout() {
this.authservice.logOutSuccess(true);
this.router.navigate(["/login"]);
this.cookieService.delete(TPIConstants.AUTH_TOKEN);
}
Here in the header component, if i click on logout i am clearing the cookie, so the screen redirects to login page.
But in the landing page, i have add new button, when i click on that it opens the router in the new tab,
Landing.html:
<a class="btn btn-light" target="_blank" [routerLink]="['/profile']"> Add New</a>
Profile Screen opens in new Tab now.
So, i have used a common service called auth.service in which i have used subject
auth.service.ts:
public detectLogOutSubject = new Subject<any>();
logOutConfirmed$ = this.detectLogOutSubject.asObservable();
logOutSuccess(value) {
this.detectLogOutSubject.next(value);
}
so when i click on logout, it comes to the authservice and triggers this event, and in profile page i have written like this in the constructor method
profile.component.ts: and app.component.ts
constructor(){
this.subscription = this.authService.logOutConfirmed$.subscribe(
res => {
alert(res)
});
}
Profile.html:
<div>
<button class="btn btn-secondary" onclick="window.close();" title="Close Window">
<i class="fas fa-times fa-1x"></i>
</button>
</div>
In profile html, i have the above div section, if that click triggered also, it will close the tab, but i am not able to get the event from logout function to profile screen/app.component also, i am struck, no where getting how to proceed
Because you aren't using a window.open() to open the new tab, your Javascript will not have permission to close the tab. If closing the tab is important, then you need to use window.open() to open the tab and then you can use window.close() to close it when you are ready.
More discussion about the security and permissions can be found here.
I want to reload my current page with onclick function, for this how to get my current route name in blade file.
This is my code:
<li class="dropdown user user-menu" onclick="window.location='{{ Route::current() }}'" style="cursor: pointer;">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="livicon" data-name="refresh" data-loop="true" data-color="#42aaca"
data-hovercolor="#42aaca" data-size="28"></i>
</a>
</li>
What is the best way to get the current route?
I want to use it on function onclick.
With Below code you can know more about your current route.
$route = Route::current();
$name = Route::currentRouteName();
$action = Route::currentRouteAction();
Reference : Link
Hope it will help!
Best way to get current url in Laravel blade:
onclick="window.location='{{ Request::url() }}'"
You can reload current page like this:
onclick="window.location.reload()"
There is no need to set current route in blade it's possible with javascript abilities.
I am working on ionic framework. So I am confused with using ui-sref and href. For example for tabs we use ui-sref as we can have various states all linked to some main (base) url.
eg
.state('dashboard', {
url: "/dashboard",
templateUrl: 'templates/dashboard.html',
controller: 'dashboardCtrl'
})
.state('dashboard.active', {
url: '/active',
views: {
'active': {
templateUrl: 'templates/active.html',
controller: 'ActiveCtrl'
}
}
})
My dashboard page has tabs whish have various various states now if I want to move to a diffrent template from one of these states or templates (eg to active.html)
eg.
//active.html
<li class="item">
<a class="button button-positive" ui-sref="dashboard.editClaim"> Edit Claim
</a>
</li>
or
<li class="item">
<a class="button button-positive" href="#/dashboard/editClaim"> Edit Claim
</a>
</li>
here should i use ui-sref or href.
Also editclaim template has tabs should i use ui-sref there and will it work fine because currently that is the problem.
So I am wondering if I have to maintain some state till there. Thank you.
here should i use ui-sref or href.
From docs: https://github.com/angular-ui/ui-router/wiki/Quick-Reference#ui-sref
A directive that binds a link ( tag) to a state. If the state has
an associated URL, the directive will automatically generate & update
the href attribute via the $state.href() method. Clicking the link
will trigger a state transition with optional parameters. Also
middle-clicking, right-clicking, and ctrl-clicking on the link will be
handled natively by the browser.
<a ui-sref="home">Home</a> is converted to:
Home
Use ui-sref if you decided to use ui-router. This is a best practice. You can change in your code associated URL for the same state and you don't need to maintain your links.
Developers rarely use href for example in big lists for better performance to avoid additional watchers, but hope its not your case
<a class="button button-positive" ui-sref="dashboard.editClaim"> Edit Claim
</a>
is going to get convert in:
<a class="button button-positive" href="#/dashboard/editClaim"> Edit Claim
</a>
in your browser since ui-sref is just a simple directive provided by angular. For more info:
https://scotch.io/tutorials/3-simple-tips-for-using-ui-router
What's next? You should use ui-sref when using ui-router
I'm trying to route to a reset page from the login page of the webapp i'm working on but nothing happens when I click on "forgot Password". when I replace #/login with #/reset in the address bar the view changes to the reset page so I know the route is setup correctly. Any idea what i'm doing wrong?
My code:
in my login template:
<a href="#" class="forgotPassword" ng-click="forgotPassword()">Forgot Password?
In my login controller:
$scope.forgotPassword = function(){
$location.path('/reset');
}
whenever using anchor tag and want to redirect by using ng-click, do not use href
for you remove the href
now your template look like this..
<a class="forgotPassword" ng-click="forgotPassword()">Forgot Password?
Have you tried to redirect your view with the "href" tag instead of the "ng-click" function?
Forgot Password?