সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
আপনার নেভিগেশন গ্রাফের জন্য কম্পাইল-টাইম টাইপ নিরাপত্তা প্রদান করতে আপনি অন্তর্নির্মিত টাইপ নিরাপদ API ব্যবহার করতে পারেন। যখন আপনার অ্যাপ নেভিগেশন কম্পোজ বা নেভিগেশন কোটলিন ডিএসএল ব্যবহার করে তখন এই APIগুলি উপলব্ধ হয়৷ এগুলি Navigation 2.8.0 হিসাবে উপলব্ধ।
এই APIগুলি XML ব্যবহার করে নির্মিত নেভিগেশন গ্রাফগুলিতে সেফ আর্গস যা প্রদান করে তার সমতুল্য।
রুট সংজ্ঞায়িত করুন
রচনায় টাইপ-নিরাপদ রুটগুলি ব্যবহার করতে, আপনাকে প্রথমে আপনার রুটগুলিকে প্রতিনিধিত্ব করে এমন সিরিয়ালাইজেবল ক্লাস বা অবজেক্টগুলিকে সংজ্ঞায়িত করতে হবে।
আপনার রুটের জন্য কোন ধরনের ব্যবহার করবেন তা নির্ধারণ করতে নিম্নলিখিত নিয়মগুলি ব্যবহার করুন:
অবজেক্ট : আর্গুমেন্ট ছাড়াই রুটের জন্য একটি অবজেক্ট ব্যবহার করুন।
ক্লাস : আর্গুমেন্ট সহ রুটের জন্য একটি ক্লাস বা ডেটা ক্লাস ব্যবহার করুন।
KClass<T> : যদি আপনার আর্গুমেন্ট পাস করার প্রয়োজন না হয়, যেমন প্যারামিটার ছাড়া একটি ক্লাস, অথবা এমন একটি ক্লাস যেখানে সমস্ত প্যারামিটারের ডিফল্ট মান থাকে ব্যবহার করুন
যেমন: Profile::class
সব ক্ষেত্রে অবজেক্ট বা ক্লাস অবশ্যই সিরিয়ালাইজেবল হতে হবে।
যেমন:
// Define a home route that doesn't take any arguments@SerializableobjectHome// Define a profile route that takes an ID@SerializabledataclassProfile(valid:String)
আপনার গ্রাফ তৈরি করুন
পরবর্তী, আপনাকে আপনার নেভিগেশন গ্রাফ সংজ্ঞায়িত করতে হবে। আপনার নেভিগেশন গ্রাফে গন্তব্য হিসেবে কম্পোজেবলকে সংজ্ঞায়িত করতে composable() ফাংশন ব্যবহার করুন।
অবশেষে, আপনি রুটের উদাহরণটি পাস করে navigate() ফাংশন ব্যবহার করে আপনার কম্পোজেবলে নেভিগেট করতে পারেন:
navController.navigate(Profile(id=123))
এটি ব্যবহারকারীকে নেভিগেশন গ্রাফে composable<Profile> গন্তব্যে নেভিগেট করে। যেকোন নেভিগেশন আর্গুমেন্ট, যেমন id , NavBackStackEntry.toRoute ব্যবহার করে Profile পুনর্গঠন করে এবং এর বৈশিষ্ট্যগুলি পড়ার মাধ্যমে প্রাপ্ত করা যেতে পারে।
এই পৃষ্ঠার কন্টেন্ট ও কোডের নমুনাগুলি Content License-এ বর্ণিত লাইসেন্সের অধীনস্থ। Java এবং OpenJDK হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-07-29 UTC-তে শেষবার আপডেট করা হয়েছে।
[[["সহজে বোঝা যায়","easyToUnderstand","thumb-up"],["আমার সমস্যার সমাধান হয়েছে","solvedMyProblem","thumb-up"],["অন্যান্য","otherUp","thumb-up"]],[["এতে আমার প্রয়োজনীয় তথ্য নেই","missingTheInformationINeed","thumb-down"],["খুব জটিল / অনেক ধাপ","tooComplicatedTooManySteps","thumb-down"],["পুরনো","outOfDate","thumb-down"],["অনুবাদ সংক্রান্ত সমস্যা","translationIssue","thumb-down"],["নমুনা / কোড সংক্রান্ত সমস্যা","samplesCodeIssue","thumb-down"],["অন্যান্য","otherDown","thumb-down"]],["2025-07-29 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],null,["# Type safety in Kotlin DSL and Navigation Compose\n\nYou can use built-in type safe APIs to provide compile-time type safety for your\nnavigation graph. These APIs are available when your app uses the [Navigation\nCompose](/jetpack/compose/navigation) or [Navigation Kotlin DSL](/guide/navigation/navigation-kotlin-dsl). They are available as of `Navigation\n2.8.0`.\n\nThese APIs are equivalent to what [Safe Args](/guide/navigation/navigation-pass-data#Safe-args) provides to navigation graphs\nbuilt using XML.\n\nDefine routes\n-------------\n\nTo use type-safe routes in Compose, you first need to define serializable\nclasses or objects that represent your routes.\n\nTo define serializable objects use `@Serializable` annotation provided by the\n[Kotlin Serialization plugin](https://kotlinlang.org/docs/serialization.html).\nThis plugin can be added to your project by [adding these\ndependencies](/guide/navigation#set-up).\n\nUse the following rules to decide what type to use for your route:\n\n- **Object**: Use an object for routes without arguments.\n- **Class**: Use a class or data class for routes with arguments.\n- **`KClass\u003cT\u003e`** : Use if you don't need to pass arguments, such as a class without parameters, or a class where all parameters have default values\n 1. For example: `Profile::class`\n\nIn all cases the object or class must be serializable.\n\nFor example: \n\n // Define a home route that doesn't take any arguments\n @Serializable\n object Home\n\n // Define a profile route that takes an ID\n @Serializable\n data class Profile(val id: String)\n\n### Build your graph\n\nNext, you need to define your navigation graph. Use the [`composable()`](/reference/kotlin/androidx/navigation/NavGraphBuilder#(androidx.navigation.NavGraphBuilder).composable(kotlin.collections.Map,kotlin.collections.List,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function2))\nfunction to define composables as destinations in your navigation graph. \n\n NavHost(navController, startDestination = Home) {\n composable\u003cHome\u003e {\n HomeScreen(onNavigateToProfile = { id -\u003e\n navController.navigate(Profile(id))\n })\n }\n composable\u003cProfile\u003e { backStackEntry -\u003e\n val profile: Profile = backStackEntry.toRoute()\n ProfileScreen(profile.id)\n }\n }\n\nObserve the following in this example:\n\n- `composable()` takes a type parameter. That is, `composable\u003cProfile\u003e`.\n- Defining the destination type is a more robust approach than passing a [`route`](/reference/kotlin/androidx/navigation/NavGraphBuilder#(androidx.navigation.NavGraphBuilder).composable(kotlin.String,kotlin.collections.List,kotlin.collections.List,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function2)) [string](/reference/kotlin/androidx/navigation/NavGraphBuilder#(androidx.navigation.NavGraphBuilder).composable(kotlin.String,kotlin.collections.List,kotlin.collections.List,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function2)) as in `composable(\"profile\")`.\n- The route class defines the type of each navigation argument, as in `val id:\n String`, so there's no need for [`NavArgument`](/reference/kotlin/androidx/navigation/NavArgument).\n- For the profile route, the `toRoute()` extension method recreates the `Profile` object from the [`NavBackStackEntry`](/reference/androidx/navigation/NavBackStackEntry) and its arguments.\n\nFor more information on how to design your graph in general, see the [Design\nyour Navigation graph](/guide/navigation/design) page.\n\n### Navigate to type safe route\n\nFinally, you can navigate to your composable using the [`navigate()`](/reference/kotlin/androidx/navigation/NavGraphBuilder#(androidx.navigation.NavGraphBuilder).composable(kotlin.collections.Map,kotlin.collections.List,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function2))\nfunction by passing in the instance of the route: \n\n navController.navigate(Profile(id = 123))\n\nThis navigates the user to the `composable\u003cProfile\u003e` destination in the\nnavigation graph. Any navigation arguments, such as `id`, can be obtained by\nreconstructing `Profile` using `NavBackStackEntry.toRoute` and reading its\nproperties.\n| **Important:** Because the parameters of the data class are typed, when you pass an instance of that class to `navigate()`, the arguments are necessarily type safe.\n\n### Additional resources\n\n- [Design your navigation graph](/guide/navigation/design)\n- [Use your navigation graph](/guide/navigation/use-graph)"]]