Is there a way to see if a Screen/Route exists in a navigation stack for React Navigation v5? - react-navigation

Depending on if a screen exists in a certain stack I need to be able to do different things in my code. I have tried my best but I haven't found anything on the matter. Is there an easy way to achieve this?

If you mean, you want to get all the routes inside the current navigator, then I think this will fix your problem.
const navigation = useNavigation();
const routes = navigation.dangerouslyGetState().routeNames;

In v.6 :
const navigation = useNavigation();
const routes = navigation.getState().routeNames;

In my v5.7 it was:
const routes = navigation.getRootState().routeNames;
Which returns an array of all available routes, so then I was just able to check if it exist by doing this:
if (routes.includes('YourRouteNameHere')) {
console.log('Route exist!');
}

Related

is there a way I can fix my useSelector hook that is showing undefined?

I am learning to build a add to cart functionality using redux-toolkit. I clone this project online so I can follow step by step. I ran into trouble when I want to use the selector to select my state it says not defined.
Here is my codesandbox code please help. https://codesandbox.io/s/vigorous-wind-n8mi3v?file=/src/centralStore.js/store.js
I need to say one more time that my main issue is
state not been defined when I use the selector hook. It renders my forEach useless.
Please help.
In your App.js, you should modify to this
const cart = useSelector(( state)=> state.reducer.cart)
(Originally, your code was
const cart = useSelector(( state)=> state.cart)
because in your store.js, you use one more layer of "reducer"

CarouselView.FormsPlugin get index of specific page

I'm using Carousel View by alexrainman for creating custom wizard.
I need to get index of specific page by its type (I don't know exactly which index would that page have).
Something like this:
var indexAdvanced = MyCarouselView.GetIndex<ContentView>(typeof(AdditionalDefectParametersContentView));
but of course, this code doesn't work. While creating this question, I've got an idea with using CarouselView's ItemsSource. How to do it properly? TIA.
By the way, I've already found an answer. >_<
The resulting code is:
// My CarouselView consists of ContentViews
_indexAdvanced = MyCarouselView.ItemsSource.Cast<ContentView>().
IndexOf(view => view is AdditionalDefectParametersContentView);
So it works!
Don't know what should I do: delete this question or leave? Maybe It would be useful for somebody, so I'll leave it for now.

Vue router.push: How to check if component or content is loaded?

As per all my post, I just want to make it known that I am still new to Laravel + VueJS, so please be as detailed as possible when posting your answers or comments. Thanks.
I am using Vue's router.push() to retrieve pages. Example code as follows:
editHandler(id) {
let self = this
self.$router.push({ name: 'inventory/Suppliers/Edit', params: { id }
})
}
I planned to add a loading overlay on the onClick event but I need help to check when the component/content has been loaded so that I can hide the loading overlay. Anyone can help me how I can achieve this? Thanks.

How to access the previous route from Durandal router

Is there a way to access the previous route/instruction from the Durandal.js router? I know I can do router.navigateBack() to actually navigate back, but I want to know the route that I will navigating back to before I trigger the navigation.
Not directly I'm afraid.
router.navigateBack() is defined in router.js as
router.navigateBack = function() {
history.navigateBack();
};
And history.navigateBack() is defined in history.js as
history.navigateBack = function() {
history.history.back();
};
and history.history is an alias defined above for window.history which is part of the browser and would cause security issues if exposed.
If you want to have that functionality you'll have to implement it yourself. Possibly by intercepting router.navigate() and router.navigateBack().

yii multi-level ajaxLink

I'm designing a 3-level menu in my website, and I use yii as the php-framework.
For example:
ItemA
Item_a1
Item_a11
Item_a12
Item_a2
ItemB
...
For some reasons I'd like to use ajax to generate those sub_items.
Therefore I wrote CHtml::ajaxLink("ItemA", url, ...); and it works fine to generate the second level items, i.e Item_a1, Item_a2, ....
My problem is the when I use CHtml::ajaxLink("Item_a1", url, ...); to ajax to generate the 3rd level, it can't work.
My guess is that when the second time I generate the ajaxLink by renderPartial, yii didn't inject the corresponding js-script to the view so that the link can't work.
I don't know how to fix this problem, please help! Thanks!
You are most likely right, and there is a parameter on renderPartial() which will force including the JS code to fix this. Something like this:
$this->renderPartial(
'_partialview', // your menu view
array(), // data/variables for your view
false, // whether it should print or return the buffered output
true, // "processOutput" - false by default, this should output your JS now
);
Good luck!

Resources